Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if variable contains part of a string #676

Closed
Zubrik opened this issue Feb 16, 2016 · 1 comment
Closed

Check if variable contains part of a string #676

Zubrik opened this issue Feb 16, 2016 · 1 comment

Comments

@Zubrik
Copy link

Zubrik commented Feb 16, 2016

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.

@carljm
Copy link
Contributor

carljm commented Feb 16, 2016

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

@carljm carljm closed this as completed Feb 16, 2016
@Zubrik Zubrik mentioned this issue Mar 24, 2016
trey added a commit to trey/treypiepmeier that referenced this issue Dec 23, 2019
1. If the item is the current page, don’t show a link.
2. If it’s a subpage, still show it as being current, but include a
link back to the base of that section.

I feel like I need to rethink my Sass file structure and include
orders.

Here’s how you can search for a part of a string using `in`:
mozilla/nunjucks#676 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants