Forum for discussing general topics related to Couch.
2 posts Page 1 of 1
Hi all,

I just installed Couch for the first time and am trying to wrap my head around it.

I have a question about basic parent/child categories, and how to loop through children.

For example, let's say I made 2 templates called:

Countries.php
Cities.php

For each country, I'd like to be able to list and link to all the associated cities in it. With the city, I'd also want to be able to find the parent country.

I'm not quite sure how things are linked to parents here (the equivalent in mySQL would be something like SELECT city_name, city_url FROM countries WHERE country_name = X.

Do folders play this role, or is there a better way? Specifically,

1. For each city cloned page, how do I tell it which parent country it belongs to in the admin tool? (I assume the city template needs some kind of tag added to it to allow this?)

2. If I'm in a random page (not city or country), what would be the proper commands to loop through a specific query? For example, say on the home page I decide to feature cities in Canada. What's the syntax for looping when your current page would not be in the main path/folder/etc of the content you want?

Sorry if these are dumb questions, but as someone who usually just writes SQL to get this done, I'm struggling a bit with your syntax.

Thanks!
Hello and welcome :)

I think what you are looking for is this -
http://www.couchcms.com/docs/concepts/r ... ships.html
Since you are conversant with SQL queries, I am sure you'll find the discussion very easy to follow.

Basically create 'cities' and 'countries' as regular cloned pages then relate the cities template with the countries (so that while editing a city, we get the countries dropdown).

Listing will be done using the 'related_pages' and 'reverse_related_pages' tags (very similar to 'pages' tag and support all its parameters).

Do let us know if there is something you find confusing and need help with.

Thanks.
2 posts Page 1 of 1