mozilla/nunjucks

Check if variable contains part of a string

Closed this issue · 1 comments

Hi,

I'm defining a variable:

{% set activePage = "foo bar" %}

Then I have some html:

<body class="{{activePage}}">

Which gives me:

<body class="foo bar">

I'd like to check if 'activePage' contains at least 'foo' (and not necessarily 'bar'), but obviously this returns false:

{%if activePage == 'foo' %}

How could I check if the variable holds just one of those class names?

Thanks.

{% if 'foo' in activePage %} should work.