Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
How can I check whether the page in <cms:pages... is the first page in loop?
Is it also possible to get a value from the first page that would be listed outside the cms:pages loop?

- what I want to do is first to add the first section an "active" html class
- 2nd to use the variable "background_image" from the first page for the "body" html tag

I guess the page ID is not a reliable variable to check for since pages could be deleted. So what's the best practice to do so in couch cms? Or would it be better just to use native php function?

Code: Select all
 

<body style="background-image: url(<cms:show background_image/>);">
<!-- background from first page -->

<cms:pages masterpage='section.php' orderby="section_position" order="asc">
        <section id="<cms:show k_page_name/>-section" class="project full-height" data-background="<cms:show background_image/>">
          <!-- content goes here -->
        </section>
</cms:pages>
Hi and welcome, abimelex :)

A handy way of checking which available variables could be useful in a certain situation would be to put a <cms:dump /> tag at that place.

If you do so within the cms:pages loop, you'll find that there are atleast two variables that indicate that we are on the first page of the loop - 'k_count' and 'k_paginated_top'.

So you can use either of the two variables to set the 'active' class for the first page -
Code: Select all
<cms:pages masterpage='section.php' orderby="section_position" order="asc">
    <section id="<cms:show k_page_name/>-section" class="project full-height <cms:if k_paginated_top>active</cms:if>" data-background="<cms:show background_image/>">
        <!-- content goes here -->
    </section>
</cms:pages>

Code: Select all
<cms:pages masterpage='section.php' orderby="section_position" order="asc">
    <section id="<cms:show k_page_name/>-section" class="project full-height <cms:if k_count='1'>active</cms:if>" data-background="<cms:show background_image/>">
        <!-- content goes here -->
    </section>
</cms:pages>

Is it also possible to get a value from the first page that would be listed outside the cms:pages loop?
There can be many ways of doing this. The easiest for you would be to use the cms:pages loop twice e.g. as follows
Code: Select all
<cms:pages masterpage='section.php' orderby="section_position" order="asc" limit='1'>
<body style="background-image: url(<cms:show background_image/>);">
<!-- background from first page -->
</cms:pages>

<cms:pages masterpage='section.php' orderby="section_position" order="asc">
    <section id="<cms:show k_page_name/>-section" class="project full-height <cms:if k_paginated_top>active</cms:if>" data-background="<cms:show background_image/>">
        <!-- content goes here -->
    </section>
</cms:pages>

Please notice how we have set the 'limit' to 1 so as to fetch only one page. The rest of the params are same as that in the second cms:pages loop so we can be sure that the one page fetched would be the same as in the second loop.

Hope it helps.
2 posts Page 1 of 1