5

I'm trying to add a conditional that checks if some Matrix fields are populated. If there's content, it'll enter the content within the Matrix fields. If not it'll default to another value. However, I'm not having any luck; the code at the moment reads as follows:

    {exp:channel:entries channel="{segment_1}"}
        {matrix_primary_tag_pair}
            {matrix_field_1}
        {if matrix_field_2}
            {matrix_field_2}
            {matrix_field_3}
        {if:elseif}
               {title}
        {/if}
        {/matrix_primary_tag_pair}
    {/exp:channel:entries}

As it is, either the {title} & {matrix_field_2} {matrix_field_2} appear, or none. Can anyone offer any suggestions? Thanks

6

You should try changing your conditional to test if the content is not equal to "". Also this should not be an elseif, it should simply be and else statement

{exp:channel:entries channel="{segment_1}"}
   {matrix_primary_tag_pair}
     {matrix_field_1}
     {if matrix_field_2 != ""}
       {matrix_field_2}
       {matrix_field_3}
     {if:else}
       {title}
     {/if}
   {/matrix_primary_tag_pair}
{/exp:channel:entries}

Expression Engine evaluates "" as true coming from matrix.

Also the {if:elseif} needs a condition like:

{if:elseif matrix_field_2 == ""}

http://ellislab.com/expressionengine/user-guide/templates/globals/conditionals.html#else-and-elseif

The {if:else} is more appropriate here though Hope this helps.

| 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.