如何在树枝模板上访问数组的#options键?
我试图检查语言是否为当前语言,然后将其设置为有效语言。
我的代码如下:
<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]
...
我尝试使用link['#options']
或link.options
或link.set_active_class
访问它,但您看到sqoop import --connect jdbc:mysql://******:****/retail_db --username **** --password **** --table order_items --compress --compression-codec org.apache.hadoop.io.compress.SnappyCodec --target-dir /user/test/order_items --as-avrodatafile
,但所有这些都返回NULL。
那么我如何才能访问这些属性?
感谢您的任何建议!
答案 0 :(得分:1)
根据转储的结构,这应该是有效的:
{% set link_class = item.link['#options'].set_active_class ? 'active' %}