In Octobercms Item.viewBag.cssClass Value With More Than One Classes Use If Statement With Every Class Separately

In Octobercms Pages Plugin i can insert a CSS Class in menu item attributes. Then i can renter this value in the template using "item.viewBag.cssClass". So i can use:

{% if subitem.viewBag.cssClass == 'name' %}<li class="myname"></li>{% endif %}

The problem is when i want to use more than one classes in CSS class field.For example if i insert 2 classes in the field, name1 name2.Then i can use this:

{% if subitem.viewBag.cssClass == 'name1 name2' %}<li class="myname"></li>{% endif %}

But not this:

{% if subitem.viewBag.cssClass == 'name1' %}<li class="myname1"></li>{% endif %}

or this:

{% if subitem.viewBag.cssClass == 'name2' %}<li class="myname2"></li>{% endif %}

Is there a way on twig to identify a separate class inside of a value with 2 or more classes, so i can use if statement using any class i want?



Yes, in Twig you can use the Containment Operator.

As an example, your last conditional would change to:

{% if 'name2' in subitem.viewBag.cssClass %}<li class="myname2"></li>{% endif %}