1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.3 Add variable as class name

Discussion in 'XenForo Questions and Support' started by NeoCHI, Jun 18, 2014.

  1. NeoCHI

    NeoCHI Active Member

    Currently I'm using a bunch of if statements to check what the value is in $subCat.category_name then adding a class based on what it is:

    Code:
      <xen:if is="{$subCat.category_name} == 'Review'">
                                       <li><a href="{xen:link 'articles', $subCat}" class="ribbon categoryReview">{$subCat.category_name}</a></li>
                                    <xen:elseif is="{$subCat.category_name} == 'Release'" />
                                       <li><a href="{xen:link 'articles', $subCat}" class="ribbon categoryRelease">{$subCat.category_name}</a></li>
                                     .
                                     .
                                     .
                                    <xen:else />
                                       <li><a href="{xen:link 'articles', $subCat}" class="ribbon">{$subCat.category_name}</a></li>
    
    But I'm guessing there should be a more direct to make $subCat.category_name one of the classes of the <a> tags.
     
    Last edited: Jun 18, 2014
  2. Liam W

    Liam W Well-Known Member

    HTML:
    <li><a href="{xen:link 'articles', $subCat}" class="ribbon category{$subCat.category_name}">{$subCat.category_name}</a></li>
    <li><a href="{xen:link 'articles', $subCat}" class="ribbon category{$subCat.category_name}">{$subCat.category_name}</a></li>
    <li><a href="{xen:link 'articles', $subCat}" class="ribbon category{$subCat.category_name}">{$subCat.category_name}</a></li>
    
    and so on...
     
  3. NeoCHI

    NeoCHI Active Member

    Wow coulda sworn I tried that....anyways thanks!
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    You can also use a slightly shorter version of xen:if/else within the class declaration itself.
    For example:
    Code:
    <div class="{xen:if "{$param}", 'thisClass', 'thatClass'} anotherClass">Content</div>
     

Share This Page