0

I'm trying to Stash and output an entry from a channel. Since I also need a dynamic=no menu on the left, I've been able to use a match of the {segment_2} against the url-title to dinamically display the actual entry.

I would like to display, under the main content, its related entries, which are stored as matrix rows. Each related entry has a custom title, a custom bodycopy and a link to the actual entry. The link is stored in one of the Matrix fields as a Playa field. So far I've been able to achieve most of my requirements, but I can't seem to find a way to indicate the context in the get_list for the Playa.

Each related entry, lists links from other rows too. So, if I get 4 related results, each result lists its link and the ones from it's siblings (3+1) too.

{exp:stash:set_list name="patologie_list" parse_tags="yes" parse_depth="2"}
{exp:channel:entries channel="elements_patologie" dynamic="no"}
    {stash:entry_id}{entry_id}{/stash:entry_id}
    {stash:title}{title}{/stash:title}
    {stash:testo_patologia}{testo_patologia}{/stash:testo_patologia}
    {stash:url_title}{url_title}{/stash:url_title}
        {exp:stash:set_list:matrix name="matrix_link_patologia" context="{entry_id}" parse_tags="yes"}
            {matrix_link_patologia}
                {stash:titolo_link_patologia}{titolo_link_patologia}{/stash:titolo_link_patologia}
                {stash:testo_link_patologia}{testo_link_patologia}{/stash:testo_link_patologia}
                {exp:stash:set_list:playa parse_tags="yes" name="resources"}
                        {exp:playa:children col="link_patologia"}
                            {stash:link_patologia}{url_title}{/stash:link_patologia}
                        {/exp:playa:children}
                {/exp:stash:set_list:playa}
            {/matrix_link_patologia}
        {/exp:stash:set_list:matrix}            
{/exp:channel:entries}
{/exp:stash:set_list}

<div class="page" id="patologie">
<div class="container">
    <aside class="aside-navigation">
        <nav class="side-menu">
            <ul>
                {exp:stash:get_list name="patologie_list"}
                <li><a href="{url_title}" class="active">{title}</a></li>
                {/exp:stash:get_list}
            </ul>
        </nav>
    </aside>

    <section class="main">
        <h1>Le patologie trattate</h1>
        {exp:stash:get_list name="patologie_list" match="#^{segment_2}$#" against="url_title"}
            <h2>{title}</h2>
            {testo_patologia}

        <div class="related_entries">
            <ul>
                {exp:stash:get_list:matrix name="matrix_link_patologia" context="{entry_id}" limit="4"}
                <li>
                    <h3>{titolo_link_patologia}</h3>
                    <p>{testo_link_patologia} 
                        {exp:stash:get_list:playa name="resources"}
                        <a href="{link_patologia}">Continua</a></p>
                        {/exp:stash:get_list:playa}
                </li>
                {/exp:stash:get_list:matrix}
            </ul>
        </div>
        {/exp:stash:get_list}
    </section>
</div>
1

Try using row_id and entry_id for the context. You might also need to increase the parse_depth on the outermost stash tag to 4.

{exp:stash:set_list name="patologie_list" parse_tags="yes" parse_depth="4"}
{exp:channel:entries channel="elements_patologie" dynamic="no"}
    {stash:entry_id}{entry_id}{/stash:entry_id}
    {stash:title}{title}{/stash:title}
    {stash:testo_patologia}{testo_patologia}{/stash:testo_patologia}
    {stash:url_title}{url_title}{/stash:url_title}
        {exp:stash:set_list:matrix name="matrix_link_patologia" context="{entry_id}" parse_tags="yes"}
            {matrix_link_patologia}
                {stash:row_id}{row_id}{/stash:row_id}
                {stash:titolo_link_patologia}{titolo_link_patologia}{/stash:titolo_link_patologia}
                {stash:testo_link_patologia}{testo_link_patologia}{/stash:testo_link_patologia}
                {exp:stash:set_list:playa parse_tags="yes" name="resources" context="{row_id}-{entry_id}"}
                        {exp:playa:children col="link_patologia"}
                            {stash:link_patologia}{url_title}{/stash:link_patologia}
                        {/exp:playa:children}
                {/exp:stash:set_list:playa}
            {/matrix_link_patologia}
        {/exp:stash:set_list:matrix}
{/exp:channel:entries}
{/exp:stash:set_list}

<div class="page" id="patologie">
<div class="container">
    <aside class="aside-navigation">
        <nav class="side-menu">
            <ul>
                {exp:stash:get_list name="patologie_list"}
                <li><a href="{url_title}" class="active">{title}</a></li>
                {/exp:stash:get_list}
            </ul>
        </nav>
    </aside>

    <section class="main">
        <h1>Le patologie trattate</h1>
        {exp:stash:get_list name="patologie_list" match="#^{segment_2}$#" against="url_title"}
            <h2>{title}</h2>
            {testo_patologia}

        <div class="related_entries">
            <ul>
                {exp:stash:get_list:matrix name="matrix_link_patologia" context="{entry_id}" limit="4"}
                <li>
                    <h3>{titolo_link_patologia}</h3>
                    <p>{testo_link_patologia} 
                        {exp:stash:get_list:playa name="resources" context="{row_id}-{entry_id}"}
                        <a href="{link_patologia}">Continua</a></p>
                        {/exp:stash:get_list:playa}
                </li>
                {/exp:stash:get_list:matrix}
            </ul>
        </div>
        {/exp:stash:get_list}
    </section>
</div>

EDIT to add

If each row will only ever return a single related entry then there's no need to use set_list and get_list, and you can also do away with the Playa module tag and use the simpler field tag instead. Something like this:

{exp:stash:set_list name="patologie_list" parse_tags="yes" parse_depth="4"}
    {exp:channel:entries channel="elements_patologie" dynamic="no"}
        {stash:entry_id}{entry_id}{/stash:entry_id}
        {stash:title}{title}{/stash:title}
        {stash:testo_patologia}{testo_patologia}{/stash:testo_patologia}
        {stash:url_title}{url_title}{/stash:url_title}
            {exp:stash:set_list:matrix name="matrix_link_patologia" context="{entry_id}" parse_tags="yes"}
                {matrix_link_patologia}
                    {stash:row_id}{row_id}{/stash:row_id}
                    {stash:titolo_link_patologia}{titolo_link_patologia}{/stash:titolo_link_patologia}
                    {stash:testo_link_patologia}{testo_link_patologia}{/stash:testo_link_patologia}
                    {stash:link_patologia}
                        {link_patologia var_prefix="playa"} {!-- playa field inside matrix --}
                           {playa:url_title}
                        {/link_patologia}
                    {/stash:link_patologia}
                {/matrix_link_patologia}
            {/exp:stash:set_list:matrix}
    {/exp:channel:entries}
{/exp:stash:set_list}

<div class="page" id="patologie">
<div class="container">
    <aside class="aside-navigation">
        <nav class="side-menu">
            <ul>
                {exp:stash:get_list name="patologie_list"}
                <li><a href="{url_title}" class="active">{title}</a></li>
                {/exp:stash:get_list}
            </ul>
        </nav>
    </aside>

    <section class="main">
        <h1>Le patologie trattate</h1>
        {exp:stash:get_list name="patologie_list" match="#^{segment_2}$#" against="url_title"}
            <h2>{title}</h2>
            {testo_patologia}

            <div class="related_entries">
                <ul>
                    {exp:stash:get_list:matrix name="matrix_link_patologia" context="{entry_id}" limit="4"}
                    <li>
                        <h3>{titolo_link_patologia}</h3>
                        <p>{testo_link_patologia}
                            <a href="{link_patologia}">Continua</a></p>
                    </li>
                    {/exp:stash:get_list:matrix}
                </ul>
            </div>
        {/exp:stash:get_list}
    </section>
</div>
| improve this answer | |
  • Thanks but it doesn't work. Now I get 0 results. – Milksamsa Jan 13 '15 at 16:40
  • Sorry. I forgot to stash the row_id. I still get 4 results though. – Milksamsa Jan 13 '15 at 16:45
  • For debug purposes please check this file: imgur.com/WmptVH1 I've added the {row_id} - {entry_id} to the links. – Milksamsa Jan 13 '15 at 17:05
  • updated answer... – James Smith Jan 13 '15 at 17:22
  • Thanks… Now I get just one link… but I'm debugging it's rendering… what's the purpose of that Playa prefix? – Milksamsa Jan 13 '15 at 17:32

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.