if string contains substring twig
Solutions
url()
returns an array, as 4x4 says. You can see this if you do a for loop on the variable.
path()
, however, seems to return a string that you can do your operation on. But it won't include hostname.
The twig function url()
returns a render array, when you render it with the twig filter |render
you get a markup object and when you render it again you get a string, which you can check whether it contains a substring:
{% set url = url('<current>') %}
{% if 'test' in url|render|render %}
<p>url contains "test"</p>
{% endif %}
How to check if menu item contains a word using twig
in the menu.html.twig theme template, I want to check if a menu item title contains a specific word. so I tried this codes, but none of them worked. and I have the items: 'separator 1', ' separator 2', 'separator' but couldn't solve the problem!
String Overrides is not overriding the "Read more" string
I've filed a support request on drupal.org about this question, but I figured I should ask here as well because someone could know the answer. I want to change the "Read more" link in teasers so that it says "Full story". I was pointed to the String Overrides module which supposedly makes it very simple to change the built-in strings. The UI isn't ...
PHP match string parent level URL string only. Ignore sub-directory paths
I'm looking to implement a simple conditional within a template file (Drupal 7) that checks the URL path and only operates on the condition when the string is exact/page is the parent. At the moment, I have a conditional working, but the condition still executes for sub pages of the URL string when matched. E.g: This still operates for anything hie...