2

I would like to attach different CSS classes for different types of file within a Matrix field. I have tried:

<a href="{group_files}{if group_files_file}{group_files_file}{if:else}{group_files_link}{/if}{/group_files}" class="{group_files}{if "{extension}"=="docx"}doc{if:elseif "{extension}"=="doc"}doc{if:elseif "{extension}"=="pdf"}pdf{if:else}txt{/if}{/group_files}" title="{group_files}{group_files_title}{/group_files}">{group_files}{group_files_title}{/group_files}</a>

But this always defaults to txt. Any ideas where I'm going wrong?

Thanks in advance

0

Have you tried using either Switchee or Ifelse instead of the native if/else? It could be an issue of parse order which is messing this up for you.

Low has a very good explanation of ExpressionEngine Parse Order.

0

Does removing the forced parse help? Change "{extension}" to just extension.

{group_files}
{if extension == "docx"}
    doc
{if:elseif extension == "doc"}
    doc
{if:elseif extension == "pdf"}
    pdf
{if:else}
    txt
{/if}
{/group_files}

Or with IfElse add-on just add wrapping tag pair:

{exp:ifelse parse="inward"}  
  {group_files}
    {if extension == "docx"}
      docx
    {if:elseif extension == "doc"}
      doc
    {if:elseif extension == "pdf"}
      pdf
    {if:else}
      txt
    {/if}
  {/group_files}
{/exp:ifelse}

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.