Problems, need help? Have a tip or advice? Post it here.
10 posts Page 1 of 1
hi – please could you point me in the right direction - I'm sure it’s a simple thing I want to achieve!

I have a template called engagements.php (non-cloneable) and a cloneable template called concert-dates.php.

On engagements.php I want to have sub-navigation consisting of ‘Upcoming’ and ‘Previous’ - i.e. simply split all the concert-dates.php into 2 lists - one in the past and one in the future.

The default listing on engagements.php will be all the upcoming concert-dates.php i.e. from today onwards. On selecting ‘Previous’ the listing will show concert-dates.php in the past.

I think I can simply use the following for ‘Upcoming’

Code: Select all
<cms:pages masterpage='concert-dates.php' order='asc' show_future_entries='1' start_on="<cms:date format='Y-m-d' gmt='1' />" >


and the following for ‘Previous’

Code: Select all
<cms:pages masterpage='concert-dates.php' order='asc' show_future_entries='0 >


However, having thought this was simple to do, I am struggling to tie together the <cms:pages> tags with the sub-navigation for 'Upcoming' and 'Previous' and the listings returned by the <cms:pages> tag.

Thanks.
Hi,

I am not sure how exactly you are defining 'Upcoming' so I am posting code for both the scenarios that, to my mind, can be termed upcoming -

1. The following should fetch all pages from today onwards *including today*
Code: Select all
<cms:pages limit='5' masterpage='concert-dates.php' order='asc'  show_future_entries='1' start_on="<cms:date format='Y-m-d' />">
   ...
</cms:pages>

while this should fetch all previous pages *excluding today*
Code: Select all
<cms:pages limit='5' masterpage='concert-dates.php' order='asc' stop_before="<cms:date format='Y-m-d' />" >
   ...
</cms:pages>


2. If, however, by 'Upcoming' you mean all pages that are in future from *this instant* onwards, this should do it
Code: Select all
<cms:pages masterpage='concert-dates.php' order='asc' show_future_entries='1' start_on="<cms:date format='Y-m-d H:i:s' />">
   ...
</cms:pages>

where the following fetches all pages published before the current instant
Code: Select all
<cms:pages masterpage='concert-dates.php' order='asc' show_future_entries='0' >
   ...
</cms:pages>

Does this help? Please let me know.
Thanks.
great thanks, No. 1 is ideal. I'm just not sure now, how to get these separate lists of pages - Upcoming / Previous to display via two sub-navigation links within the page i.e. how to switch between the 2 different lists. So within the page, click on 'Previous' to display past events, and then click back to 'Upcoming' and display 'future' events. I realise I should know this - but I can't find an example of quite this scenario (my previous page sub nav has been tied in with folders, archives etc).
Not sure if I understood the problem completely but, I think, using JavaScript could be one method (i.e. render both lists on the page via Couch but hide/toggle one of the two using JS).

Another method could be passing a GET parameter through the URL and then rendering via Couch just that list that was requested.
The latter option suggested by KK should be perfectly sufficient to start with, regardless if you want to add any JS to improve the experience.

Upcoming: yoursite.com/engagements/
Previous: yoursite.com/engagements/?prev=1

Code: Select all
<a href="<cms:add_querystring "<cms:link 'engagements.php'/>" 'prev=1'/>">Previous</a>
<a href="<cms:link 'engagements.php'/>">Upcoming</a>

<cms:if "<cms:gpc 'prev' method='get'/>">
   <!-- Previous Pages Tag -->
<cms:else/>
   <!-- Upcoming Pages Tag -->
</cms:if>
Aah, thanks so much. I'll try using the GET method. I had been assuming that there was a way to do this with a Couch tag - and was scratching my head over it ... will try tomorrow.
Just what I wanted (I used cheesypoof's code) - 2 sub links for viewing events in the past and the future. THANKS!

One detail - I haven't been able to find anything to distinguish between the 2 URLs and therefore haven't been been able to highlight the current link, which would be nice.
The same logic that is used to show the appropriate pages tag can be used to highlight the current link.

To make this code a bit nicer so we don't have to use the gpc tag multiple times, lets set a flag variable that we can use later:
Code: Select all
<cms:set previous='0'/>
<cms:if "<cms:gpc 'prev' method='get'/>">
   <cms:set previous='1'/>
</cms:if>

Now we can use this variable in all of our if tags:
Code: Select all
<a href="<cms:add_querystring "<cms:link 'engagements.php'/>" 'prev=1'/>"<cms:if previous> class="current"</cms:if>>Previous</a>
<a href="<cms:link 'engagements.php'/>"<cms:if "<cms:not previous/>"> class="current"</cms:if>>Upcoming</a>

<cms:if previous>
   <!-- Previous Pages Tag -->
<cms:else/>
   <!-- Upcoming Pages Tag -->
</cms:if>

Let me know if this helps.
Awesome! Huge thanks.

This is clever. I wouldn't have been able to come up with this - it's really neat. To my eye it seems unexpected that the sequence of the code would allow the flag to be correctly set for Previous - because the <a> tag comes after the setting of the flag!

Anyway, I hate to see current position not highlighted on a website - problem beautifully solved! Thanks!
I don't mean to belabor this issue, but I think perhaps my use of the add_querystring tag is creating some confusion over what is occurring. This tag does not play any role in determining when we can access the query string values with the gpc tag. It merely accepts a URL, takes care to append parameters to the query string portion of it in the correct format, and returns a new URL. See the docs (http://www.couchcms.com/docs/tags-reference/add_querystring.html) for a better explanation. The following two lines produce the exact same result in your use case because only one query string parameter is used.
Code: Select all
<cms:add_querystring "<cms:link 'engagements.php'/>" 'prev=1'/>
<cms:link 'engagements.php'/>?prev=1

The 'previous' variable is able to be set to '1' because the only condition for doing so is that in your browser address bar '?prev=1' is placed at the end of the URL. No other factor is involved, including whether the Previous link is actually clicked or the URL is manually typed out...
10 posts Page 1 of 1