简体   繁体   English

如何串联url(&#39; <front> &#39;)+ Twig drupal中的字符串

[英]How to concatenate url('<front>') + string in Twig drupal

I am trying to select a path that is equal to (http: // myweb / app) in html.html.twig of drupal. 我正在尝试在drupal的html.html.twig中选择一个等于(http:// myweb / app)的路径。

For this, I'm using URL, but when trying to concatenate an array (which would be url ('<front>') with a string returns ArrayString) obviously this is wrong. 为此,我使用的是URL,但是当尝试连接一个数组(该字符串为url ('<front>')和一个字符串会返回ArrayString)时,这显然是错误的。

{% set url_app_front = url('<front>') %}
{% set url_app = url_app_front ~ 'app' %}

Arrayapp Arrayapp

It is clear that url('<front>') is an array, but the #Markup that returns clean is http: / myweb /. 显然url('<front>')是一个数组,但是返回clean的#Markup是http:/ myweb /。 I have tried to select it but... dont know how. 我试图选择它,但是...不知道如何。

{{ url('<front>').markup }}

What I'm looking for would be something like ... 我正在寻找的东西会像...

{% set url_app = url('<front>') ~ 'app' %}
{% set url = url('<current>') %}
{% if '{{ url_app }}' in url|render|render %}

To select http://myweb/app 选择http:// myweb / app

If there is any other way to achieve it, I am also willing to read 如果还有其他方法可以实现,我也很愿意阅读

We have to convert this array to a string (thanks to #markup) with render_var() 我们必须使用render_var()将数组转换为字符串(感谢render_var()

I got it in https://drupal.stackexchange.com/questions/243648/concatenate-url-in-twig (my bad for not looking there first) 我在https://drupal.stackexchange.com/questions/243648/concatenate-url-in-twig中得到的(我不好因为没有首先看那里)

{% set url_app = render_var(url('<front>')) ~ 'app' %}
{% set url = url('<current>') %}
{% if url_app in url|render|render %}
....
{% endif %}

http://myweb/app http:// myweb / app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM