Search code examples
tagswidgetblogssilverstripe

Silverstripe Blog Tags add class for current tag filter


Sorry I'm kinda new to Silverstripe.

Is there a way to add a active/current class to the BlogTagsWidget.ss list items?

Cheers


Solution

  • Assuming that the BlogController is the current controller when BlogTagsWidget.ss is rendered, you may be able to use this method directly to check it in the template, e.g.

    <% loop $Tags %>
        <% if $CurrentTag && $CurrentTag.ID == $ID %>
            Current
        <% else %>
            Not current
        <% end_if %>
    <% end_loop %>
    

    If it's not available then you may need to add some extra code to provide the current tag boolean in BlogTagsWidget::getTags().