3

I'm using Stash and Switchee to build some paginated News entries. However, when I click through to Page 2 and beyond, my page title changes to the latest entry in the CMS. Wondered if anyone had a solution for this?

As you can see from the code below, I have a news index page - which I have created as a Page in the CMS at mydomain.tld/news and then within this same template I'm also building up some paginated results rows of news articles. I set a title value for the index page which works fine (this then gets pulled through to the embedded _layouts/index page with the tag {exp:stash:get name="title"}.

Content of _layouts/index;

<body id="page mobile-view" class="off-canvas hide-extras {exp:stash:get name='body_class'}">

<div id="size"></div>

<div class="container">

<h1>{exp:stash:get name="page_title"}</h1>

{exp:stash:get name="content"}

</div>

</body>

</html>

Content of news/index;

{embed="_layouts/index"}
{preload_replace:channel="news"}

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

    {!-- News index --}
    {case value="#^P(\d+)$#|''"}

        {exp:channel:entries
            channel="page"
            status="open"
            limit="1"
            {global:channel_disable_most}
        }

            {exp:stash:set name="page_title"}{title}{/exp:stash:set}

        {/exp:channel:entries}

        {exp:stash:set parse_tags="yes" parse_conditionals="yes"}

            {stash:results_rows}
                {exp:channel:entries
                    channel="{channel}"
                    orderby="date"
                    sort="desc"
                    limit="6"
                    dynamic="no"
                    status="not closed"
                    paginate="bottom"
                }

                    <div class="twelve columns other_news">
                        <div class="three columns">
                            <a href="{site_url}news/{url_title}" title="{title}">
                                {exp:ce_img:pair
                                    src="{news_leaderimage}"
                                    height="218"
                                    width="380"
                                    attributes='style="width:100%;"'
                                }
                                    <img src="{made}" alt="{title}" />
                                {/exp:ce_img:pair}
                            </a>
                        </div>
                        <div class="nine columns">
                            <div class="sub-padding3a">
                                <h1 class="title4"><a href="{site_url}news/{url_title}">{title}</a></h1>
                                <p class="paragraph1 date">Added <span>{entry_date format="{global:date_short}"}</span></p>
                                <div class="paragraph1">
                                    <p>{news_summary} <a class="oLink" href="{site_url}news/{url_title}" title="Read More about {title}">&#0187; Read More</a></p>
                                </div>
                            </div>
                        </div>
                    </div>

                    {stash:absolute_results}{absolute_results}{/stash:absolute_results}

                    {paginate}
                        {stash:pagination_summary}
                            <div style="width:30%; float:left;">
                                Page {current_page} of {total_pages}
                            </div>
                        {/stash:pagination_summary} 
                        {stash:pagination_links}
                            {pagination_links}
                                <div class="refit">
                                    <div class="refit-inner">
                                        {previous_page}<a href="{pagination_url}"><strong>&laquo; Previous</strong></a>{/previous_page}

                                        <div class="push">
                                            {page}<a href="{pagination_url}" class="page-{pagination_page_number} {if current_page}selected{/if}">{pagination_page_number}</a>{/page}
                                            {next_page}<a href="{pagination_url}"><strong>Next &raquo;</strong></a>{/next_page}
                                        </div>
                                    </div>
                                </div>
                            {/pagination_links}
                        {/stash:pagination_links}
                    {/paginate}
                    {stash:all_items}{absolute_results}{/stash:all_items}
                    {if count == 1}{stash:first_item}{absolute_count}{/stash:first_item}{/if}
                    {if count == total_results}{stash:last_item}{absolute_count}{/stash:last_item}{/if}
                {/exp:channel:entries}
            {/stash:results_rows}

        {/exp:stash:set}

        {exp:stash:set name="content"}

            {exp:stash:get name="results_rows"}
            {exp:stash:get name="pagination_summary"}
            {exp:stash:get name="pagination_links"}

        {/exp:stash:set}

    {/case}

{/exp:switchee}

Look forward to any helping fixing this bug.

Thank you. :)

  • 1
    And what's in _layouts/index? – Derek Hogue Jan 11 '13 at 13:22
  • Updated to add the markup from _layouts/index :) – doubleplusgood Jan 11 '13 at 14:17
  • 1
    What if you changed the stash variable to something like page_title? Might be some variable collision going on here. – Derek Hogue Jan 11 '13 at 14:33
  • 3
    Can't spot the underlying problem right now but I've noticed a problem with the way you capture the {title}. Never use {exp:stash:set_value value="..."} to capture a variable that might contain quotes, as a page title might - these can break the EE parser when passed in a parameter. Use the tag pair {exp:stash:set name="title"}{title}{/exp:stash:set} instead. – Mark Croxton Jan 11 '13 at 19:26
  • 1
    Another problem, you've got an extra double quote in the case value: {case value="#^P(\d+)$#|"""}. That should be a pair of single quotes: {case value="#^P(\d+)$#|''"} – Mark Croxton Jan 11 '13 at 19:32
0

You might have to hard-code the entry_id for your news entry in the pages channel:

{exp:channel:entries
  channel="page"
  status="open"
  entry_id="5"
  dynamic="no"
  limit="1"
  {global:channel_disable_most}
 }

Or perhaps hard-code the URL title, either directly or with {segment_1} (assuming the URL title for the page entry is news:

{exp:channel:entries
  channel="page"
  status="open"
  url_title="{segment_1}"
  dynamic="no"
  limit="1"
  {global:channel_disable_most}
 }

What's happening is that when you leave the index and are on a paginated page (like /news/P5), the URL no longer exactly matches your index page's Pages URI of /news. Because there's no exact match, the entries tag does its default behavior and returns the latest entry in EE.

| improve this answer | |
1

In your example when segment_2 is empty or P1, P2, etc. you are setting the page_title, but that particular channel:entries tag is still dynamic (e.g. no dynamic="no" parameter). If there is no entry with a P2 title, that channel:entries tag will fall back to showing a list of entries instead, which you just limit to 1.

The solution is to also set dynamic=no for the P1 and empty segment. However a better solution is to organize your switchee a bit to catch more clear cases.

| improve this answer | |

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.