Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
hello ... I am using relationships for the first time and, grappling to get it working, wanted to check that what I am trying to do is do-able using this method. Fairly simple really, I would have used dynamic folders, but clones of work.php (i.e. work items) can belong to more than 1 category. I want to have sub-navigation/filtering at the top of the work.php listing page to show work items by category.

So I have created a relationship between work.php and work-categories.php and get the list of work-categories showing up in the Admin Panel for work.php. Now I have hit a brick wall! Here is the work-categories.php template:
Code: Select all
<?php require_once( 'admin/cms.php' ); ?>
<cms:template title='Work categories' clonable='1' commentable='0' order='50'>
</cms:template>
<?php COUCH::invoke(); ?>

And in work.php the editable region is:
Code: Select all
<cms:editable type='relation' name='work_category' label='Work category' masterpage='work-categories.php' />

I've tried variations of the related_pages and reverse_related_pages tags within work.php but nothing is happening.
Any hints or tips much appreciated!
The related_pages tag needs to be used within the context of a page view, either real (cloned page) or created such as a page loop while on a list view. Without this, no work_category is available for use.

I'm not sure if I am understanding your use case accurately, but try this:
Code: Select all
<cms:pages>
   <cms:related_pages 'work_category'>
      <cms:show k_page_title/>
   </cms:related_pages>
</cms:pages>

If however you merely want to display the listing of categories you could do:
Code: Select all
<cms:pages masterpage='work-categories.php'>
   <cms:show k_page_title/>
</cms:pages>
thanks, yes I can now see a list of work-categories. To clarify what I want to achieve - to create a link out of each work category, which acts as a filter for the work.php listing page. So on clicking for example 'category 3' only those work items which have the checkbox ticked for 'category 3' show on the listing page for work.php.

On examining the example given in the documention:
<cms:pages masterpage='artists.php' page_name='john-lennon'>
<h3>Albums of John Lennon:</h3>
<cms:related_pages 'artist_albums' >
<!-- All variables of 'albums.php' are available here -->
<cms:show k_page_title /><br/>
</cms:related_pages>
</cms:pages>
I am wondering if it is possible to do what I want. I need work.php to be the primary template - this is so that the list of work categories is available to select from within the admin panel when creating a work item. Then I want to be able to list all related work.php pages for a single work category - to get the filtering effect that you could easily do with Couch dynamic folders. So I want to return all the related primary template pages for a given category, which isn't what is demonstrated in the example above - I am trying to do the reverse which may not be possible. Does this make sense?
Hi potato,

Yes, it makes absolute sense.
You are actually very close to the solution. Let me take it step-by-step -
To clarify what I want to achieve - to create a link out of each work category

Simple use of cms:pages will create this listing of categories
Code: Select all
<cms:pages masterpage='work-categories.php'>
   <a href="<cms:show k_page_link />"><cms:show k_page_title/></a>
</cms:pages>

..which acts as a filter for the work.php listing page. So on clicking for example 'category 3' only those work items which have the checkbox ticked for 'category 3' show on the listing page for work.php.

In the listing we create above, if we click any link it will lead us to the 'page-view' of work-categories.php for that particular page. We can easily list all the 'work' pages related to the 'work-category' page we are visiting using the following code in work-categories.php's page-view:
Code: Select all
<cms:reverse_related_pages 'work_category' masterpage='work.php' >
    <a href="<cms:show k_page_link />"><cms:show k_page_title /></a>
</cms:reverse_related_pages>

So there you have it - the filter you wished.
The point is that it is the 'work_category.php' that acts as the filter using 'reverse_related_pages' tag.

Does this do what you were looking for? Please let me know.
Thanks.
Thanks KK - this does exactly what I was looking for! It is kind of you to say I was close to your solution, but I was actually barking up the wrong tree - I thought the filtered listing would be shown on the primary template (work.php) - what was I thinking?! ;)
5 posts Page 1 of 1
cron