Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hey,

I'm trying to list all the pages from the template services.php.

On the services_list.html snippet, which I'm including using
Code: Select all
<cms:embed "services_list.html
I'm pulling all the pages using:

Code: Select all
<cms:pages order="asc" orderby="k_page_title" masterpage="services.php"></cms:pages>


This is working just fine, when there are an even number of pages, but I was wondering whether the would be a way of checking whether or not I'd be able to check whether the number of pages is odd or even before running the cms:pages tag. For example:

Code: Select all
<cms:if masterpage="service.php" page_count="odd">
<ul class="boxes odd">
<cms:pages order="asc" orderby="k_page_title" masterpage="services.php">
<li class="box"><cms:show k_page_title /></li>
</cms:pages>
</ul>
<cms:else />
<ul class="boxes even">
<cms:pages order="asc" orderby="k_page_title" masterpage="services.php">
<li class="box"><cms:show k_page_title /></li>
</cms:pages>
</ul>
</cms:if>


I've looked at the documentation and I couldn't find anything to check whether or not a masterpage has an odd or even number of pages.

Any help would be great.
Hi and welcome @rglyall.

If I am understanding you correctly, you might want to try the following:
Code: Select all
<cms:pages masterpage='services.php' order='asc' orderby='page_title'>
   <cms:if k_paginated_top>
      <ul class="boxes <cms:if "<cms:mod k_total_records '2'/>">odd<cms:else/>even</cms:if>">
   </cms:if>

   <li class="box"><cms:show k_page_title/></li>

   <cms:if k_paginated_bottom>
      </ul>
   </cms:if>
</cms:pages>
Some things to note:

Use 'page_title' and not 'k_page_title' in the orderby parameter. k_paginated_top will be true only if the page is first in the listing. k_paginated_bottom will be true only if the page is last in the listing. To determine whether the total number of pages being listed is even or odd, we can use the modulo tag. Please let me know if you need an explanation for anything. Also, if you are ever curious what variables are available at any given location, feel free to drop in a <cms:dump/> tag.
Fantastic stuff, works great! Thanks.

Why use page_title instead of k_page_title?

Also, are there any author tags? I'd like to display different open graph meta data for each writer. What would be the best way of doing this?
The 'pages' tag documentation says to use 'page_title'.

Pages aren't associated with authors (users) currently. To replicate this, you can create a separate clonable 'Authors' template with all of the relevant information. Then on the template where you would display the Author's information, add a type 'relation' (http://www.couchcms.com/docs/tags-reference/editable/relation.html) editable region with a one-to-one relation setting (has='one'). You would then use the 'related_pages' (http://www.couchcms.com/docs/tags-reference/related_pages.html) tag to display the author.
4 posts Page 1 of 1