Nunjucks: Check if variable contains part of a string

Created on 16 Feb 2016  路  1Comment  路  Source: mozilla/nunjucks

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.

Most helpful comment

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

>All comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ziir picture ziir  路  3Comments

boutell picture boutell  路  6Comments

mintyPT picture mintyPT  路  4Comments

atian25 picture atian25  路  5Comments

felipenmoura picture felipenmoura  路  7Comments