Symfony 访问细枝模板上的链接#选项键
如何访问细枝模板上数组的#options键 我正在尝试检查该语言是否为当前语言,然后将其设置为活动语言 我的代码如下所示:Symfony 访问细枝模板上的链接#选项键,symfony,drupal,twig,drupal-8,Symfony,Drupal,Twig,Drupal 8,如何访问细枝模板上数组的#options键 我正在尝试检查该语言是否为当前语言,然后将其设置为活动语言 我的代码如下所示: <ul class="headerbar__text--language navbar-right"> {%- for key, item in links -%} {% set link_class = [ item.set_active_class ? 'active', ] %} <li{{ item.attr
<ul class="headerbar__text--language navbar-right">
{%- for key, item in links -%}
{%
set link_class = [
item.set_active_class ? 'active',
]
%}
<li{{ item.attributes.addClass(key|clean_class).addClass(link_class) }}>
{{ dump(item) }}
{%- if item.link -%}
{{ item.link }}
{%- elseif item.text_attributes -%}
<span{{ item.text_attributes }}>{{ item.text }}</span>
{%- else -%}
{{ item.text }}
{%- endif -%}
</li>
{%- endfor -%}
但是课程没有设置。如您所见,存在转储,结果如下:
array (size=4)
'link' =>
array (size=5)
'#type' => string 'link' (length=4)
'#title' => string 'German' (length=6)
'#options' =>
array (size=5)
'language' =>
object(Drupal\language\Entity\ConfigurableLanguage)[1623]
...
'attributes' =>
array (size=1)
...
'query' =>
array (size=0)
...
'ajax' => null
'set_active_class' => boolean true
'#url' =>
object(Drupal\Core\Url)[1629]
protected 'urlGenerator' =>
object(Drupal\Core\Render\MetadataBubblingUrlGenerator)[227]
...
protected 'urlAssembler' => null
protected 'accessManager' => null
protected 'routeName' => string '<front>' (length=7)
protected 'routeParameters' =>
array (size=0)
...
protected 'options' =>
array (size=0)
...
protected 'external' => boolean false
protected 'unrouted' => boolean false
protected 'uri' => null
protected 'internalPath' => string '' (length=0)
protected '_serviceIds' =>
array (size=0)
...
'#ajax' => null
'text' => string 'German' (length=6)
'text_attributes' =>
object(Drupal\Core\Template\Attribute)[1646]
protected 'storage' =>
array (size=1)
'class' =>
object(Drupal\Core\Template\AttributeArray)[1647]
...
'attributes' =>
object(Drupal\Core\Template\Attribute)[1649]
protected 'storage' =>
array (size=3)
'hreflang' =>
object(Drupal\Core\Template\AttributeString)[1650]
...
'data-drupal-link-system-path' =>
object(Drupal\Core\Template\AttributeString)[1651]
...
'class' =>
object(Drupal\Core\Template\AttributeArray)[1959]
...
数组(大小=4)
“链接”=>
数组(大小=5)
“#类型”=>string”链接(长度=4)
“#title”=>字符串“德语”(长度=6)
“#选项”=>
数组(大小=5)
“语言”=>
对象(Drupal\language\Entity\ConfigurableLanguage)[1623]
...
“属性”=>
数组(大小=1)
...
“查询”=>
数组(大小=0)
...
'ajax'=>null
“设置活动类”=>布尔值为真
“#url”=>
对象(Drupal\Core\Url)[1629]
受保护的“urlGenerator”=>
对象(Drupal\Core\Render\MetadataBubblingUrlGenerator)[227]
...
受保护的“urlAssembler”=>null
受保护的“accessManager”=>null
受保护的“routeName”=>字符串“”(长度=7)
受保护的“路由参数”=>
数组(大小=0)
...
受保护的“选项”=>
数组(大小=0)
...
受保护的“外部”=>布尔值假
受保护的“未路由”=>布尔值假
受保护的“uri”=>null
受保护的“internalPath”=>字符串“”(长度=0)
受保护的'\u serviceIds'=>
数组(大小=0)
...
“#ajax”=>null
“文本”=>字符串“德语”(长度=6)
“文本属性”=>
对象(Drupal\Core\Template\Attribute)[1646]
受保护的“存储”=>
数组(大小=1)
“类”=>
对象(Drupal\Core\Template\AttributeArray)[1647]
...
“属性”=>
对象(Drupal\Core\Template\Attribute)[1649]
受保护的“存储”=>
数组(大小=3)
“hreflang”=>
对象(Drupal\Core\Template\AttributeString)[1650]
...
“数据drupal链接系统路径”=>
对象(Drupal\Core\Template\AttributeString)[1651]
...
“类”=>
对象(Drupal\Core\Template\AttributeArray)[1959]
...
我尝试使用link['#options']
或link.options
或您可以看到的link.set\u active\u class
,访问它,但它们都返回NULL
那么我怎样才能访问这些属性呢
谢谢你的建议 根据垃圾场的结构,这应该是可行的:
{% set link_class = item.link['#options'].set_active_class ? 'active' %}