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

Is it possible to render data stored within a template outside of that template?

Here's an example of what I mean...

I have a template: animals.php
Within that template there are three defined categories: dogs, cats, whales

site.com/animals.php renders a list of all animals
site.com/animals/dogs.php renders a list of all animals in the dogs category etc.

So far, so good, all standard stuff. But here's where I'm stuck:

I have a page pets.php, the url is site.com/pets.php I need this page to render all animals from the dogs and cats categories. Can it be done?

I hope this makes sense, and any help is gratefully received!
Hi,

You can display data belonging to any Couch managed template in absolutely any other Couch managed template of your site.

The key here is the 'masterpage' param of <cms:pages>. So, for example, the following code will always show the latest 5 pages from a template named 'blog.php' *regardless* of which template you place it in (e.g. the code could be in 'contact.php' but it will still show pages from 'blog.php')
Code: Select all
<cms:pages masterpage='blog.php' limit='5'>
    ...
</cms:pages>

It is important to use the correct name for the 'masterpage' - if in doubt, you can hover your mouse pointer over the template in admin-panel sidebar and a tooltip will show the correct value.

Hope this helps.
That certainly does help! I knew there would be a simple solution. I'm impressed with Couch because stuff like this is so easy to implement.
3 posts Page 1 of 1