0

I've got a Grid field (EE2.11) where one of the columns is called "Open?" with a checkbox for "Closed" so I can turn a row off and on. I'm using a nested conditional to first filter out anything that's marked closed, then a simple conditional within that, like this simplified version:

    {exp:channel:entries channel="samples"}
        {sample_grid}
            {if sample_grid:open <> "Closed"}
                {if sample_grid:videolink == ""}
                    {sample_grid:description}
                {if:else}
                    {sample_grid:videolink}
            {/if}
        {/sample_grid}
    {/exp:channel:entries}

So two questions: (1) is there a better way to turn Grid rows off and on (I was wishing for something I could put in the channel entries tag to do the filtering)? and (2) is there a better way to filter out the closed rows than with a nested conditional?

It's all working fine, I'm just wondering if there is some performance issue with this, or if this all seems like a good way to do this.

1

To do the searching you can simply replace the outer conditional with a search tag (which has the same syntax as the channel entries search tag). The {if} tag is pretty efficient in 2.11 so not an unreasonable method for the either / or switch. Something like:

{exp:channel:entries channel="samples"}
    {sample_grid search:open="not Closed"}
        {if sample_grid:videolink == ""}
            {sample_grid:description}
        {if:else}
            {sample_grid:videolink}
        {/if}
    {/sample_grid}
{/exp:channel:entries}

HTH

| improve this answer | |
  • Thanks for putting me on the right track. As it turns out, {sample_grid search:open="not Closed"} didn't work, but {sample_grid search:open<>"Closed"} did. Not really sure why that is... Also: do you happen to know if using a search rather than a conditional considered 'better' from a performance or other point of view? – edward Nov 15 '16 at 0:04
  • Glad to be able to help. Search is usually better if you can use it, as the entries you would otherwise discard in the conditional loop are simply not sent to the template by EE - so the amount of information being shipped around is less. For small data sets the effect is tiny, but if you are pulling just a couple of entries from a channel with 100's of entries, the savings can be significant. – JCOGS Design Nov 15 '16 at 10:46

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.