1

I have a Matrix field as a Low-Variable. It contains two columns, each Playa-Fields.

First Playa-Field: All my sites Pages from my "Page"-Channel. Second Playa-Field: Every Sidebar-Block from my "Sidebar"-Channel.

I want to control all my Sidebars from one place with this structure. It allows me to create Sidebar-Groups through rows and even re-use Sidebar-Groups for two sites.

The problem: How can I check my {entry_id} (of the Page) against the {entry_id} of the first playa-field to check if I should execute this sidebar row?

I want something like below, but obviously it doesn't work. Who knows a work-around?

{exp:low_variables:parse var="lv_sidebar_pages" var_prefix="matrix"}

        {if {matrix:cell_pages:child_ids} CONTAINS {embed:page_id}}
                    {matrix:cell_sidebars}
                    {!-- Sidebar-Code --}
                    {/matrix:cell_sidebars}
        {/if}
{/exp:low_variables:parse}

I also thought about a possibility to check normally in the first Playa-Field and then skip aka. break this loop of the Matrix-Field:

    {exp:low_variables:parse var="lv_sidebar_pages" var_prefix="matrix"}

        {matrix:cell_pages}
            {if {embed:page_id} != {entry_id}} 
                BREAK THIS MATRIX LOOP.. and jump to the next row..
            {/if}
        {matrix:cell_pages}

        {matrix:cell_sidebars}
            ..so this code isn't executed
        {/matrix:cell_sidebars}
{/exp:low_variables:parse}

Thanks for the help.

1 Answer 1

1

You can limit your Matrix field to only show rows that include the current page’s entry_id using Matrix’s search param like so:

search:cell_pages="[{entry_id}]"

Just in case you might have accidentally added the same page to multiple Matrix rows, it’s probably worth throwing a limit="1" in there too.

So to throw it all together:

{exp:low_variables:parse var="lv_sidebar_pages"
                         var_prefix="matrix"
                         search:cell_pages="[{entry_id}]"
                         limit="1"}

    {matrix:cell_sidebars}
        {!-- Sidebar-Code --}
    {/matrix:cell_sidebars}

{/exp:low_variables:parse}

Depending on what else is going on in your template, the var_prefix probably isn’t necessary, but it doesn’t hurt so I left it in.

1
  • Thanks. As always the answer was right under my very nose.
    – Victor
    Jul 21, 2013 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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