0

I have deployed pagination to one of templates which should to display only 4 products on a page. Index for that template looks like:

{embed="includes/.header-product" body_color="#FFFFFF"}

        {if segment_3}{embed="includes/.nav-main"}{product}{/if}
        {if segment_2 && segment_3==""}{embed="includes/.nav-main-subcategory"}{subcategory}{/if}
        {if segment_1 && segment_2==""}{embed="includes/.nav-main"}{category}{/if}


{embed="includes/.footer"}

Switchee version of code above:

{embed="includes/.header-product" body_color="#FFFFFF"}


    {!-- Category view --}
    {if segment_1 && segment_2==""}{embed="includes/.nav-main"}{category}
        {!-- /Category view --}
    {if:else}

        {exp:switchee variable="{segment_3}" parse="inward"}

        {case value="#^P(\d+)$#|''"}
                {embed="includes/.nav-main-subcategory"}{embed="furniture/.subcategory"}
        {/case}

        {!-- Subcategory view --}
            {case value=""}
                {embed="includes/.nav-main-subcategory"}{embed="furniture/.subcategory"}
            {/case}
            {!-- /Subcategory view --}

            {!-- Single product view --}        
            {case default="Yes"}
                {embed="includes/.nav-main"}{product}
            {/case}
            {!-- /Single product view --}

        {/exp:switchee}
    {/if}

{embed="includes/.footer"}

and subcategory snippet code looks like:

<div class="container category">

    <div class="row row-category">

    {exp:channel:entries channel="products" category="{segment_2_category_id}" orderby="title" sort="asc" limit="4" paginate="bottom" dynamic="no"}

        {if no_results}
                <div class=""><p>No entries yet.</p></div>
            {/if}

            <div class="col-md-3 col-sm-6 category-item">
                <a href="{site_url}{segment_1}/{segment_2}/{url_title}">
        {product_image limit="1"}
                <img src="{product_image:image}" alt="{product_image:title}" class="img-responsive">
        {/product_image}    
                <h3>{title}</h3>
                </a>
            </div>

    {switch='|||</div><div class="row row-category">'}


    {paginate}
        <p>Page {current_page} of {total_pages} pages {pagination_links}</p>
    {/paginate}

    {/exp:channel:entries}

   </div><!--/row-->


</div><!--/container-->

First page is OK but other pages comes blank. I think I have done something wrong within index or template structure for furniture group but no clue what can be wrong.

Thanks

3

1 Answer 1

1

It seems likely that the conditional that you're using to insert your "subcategory" is getting tripped up by the presence of the segments that pagination would automatically create - segment 3 for example might be blank on your index view, but once you paginate, it's likely occupied, and as such, the terms of your condition can't be met and therefore your listing embed isn't being inserted at all. You may have an easier time with it if you use the excellent switchee add-on which could parse your conditionals earlier using switch case and allow you to detect pagination segments using regex (see the example on the devot-ee page for details).

And to Derek's point - if you don't need an embed - which you would only need if you have a need to either pass a variable (which you're not doing, based on your code), or work around native parse order - you likely could do the same thing with snippets instead and save on performance.

2
  • I thought that it must be something with that index file at the first point. Regarding using snippets it is good idea, but as I mentioned above my knowledge about EE comes from that book. But it is not too late to learn proper way ;) Jan 28, 2014 at 14:09
  • When moved code to snippet if no_results is not working. Any clue? Jan 28, 2014 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.