Before and After inside perch if

  • Hi


    I'm using perch_collection to output a list of posts. I'd like to be able to style the first post (the newest post) in the list a bit different that the rest.


    Code
    1. perch_collection('News', [
    2. 'template' => 'path/to/template/news.html',
    3. ]);


    I was hoping to use perch_item_first like this:


    Code
    1. //news.html
    2. <perch:if exists="perch_item_first">
    3. <perch:template path="path/to/template/latest.html" />
    4. <perch:else>
    5. <perch:template path="path/to/template/list.html" />
    6. </perch:if>


    list.html is using <perch:before> and <perch:after> tags, but they aren't being picked up by Perch?


    Is this intentional?



    The <perch:before> and <perch:after> tags work as expected when I move list.html out of the <perch:if>

  • Yes, I've just tried a simple demo


    Code
    1. <perch:if exists="perch_item_first">
    2. <perch:content id="post_title">
    3. <perch:else>
    4. <perch:before><ul></perch:before>
    5. <li><perch:content id="post_title"></li>
    6. <perch:after></ul></perch:after>
    7. </perch:if>


    You're right, perch:after is recognised, but perch:before isn't?


    I'd expect both to work, not just one?


    Any reason for this? Is there a workaround? :/

  • The perch:before and perch:after tags are executed only once, Before the collections are displayed, and after the collections are displayed. As your perch:before tags are executed on the second iteration- as the first is seperated - perch won't recognise the tag. You'll need to move your perch:before tags into the first if block for them to be executed. However as the first if block is always the first item, the perch:before tags are redundant. To keep things consistent you can remove the perch:before and perch:after tags and stick with perch:if


    Code
    1. <perch:if exists="perch_item_first">
    2. <perch:content id="post_title">
    3.     <ul>
    4. <perch:else>
    5. <li><perch:content id="post_title"></li>
    6. </perch:if>
    7. <perch:if exists="perch_item_last">
    8.     </ul>
    9. </perch:if>