我正在尝试制作一个树枝模板以从自定义块中获取变量,当我执行时{{ dumb() }}
它会向我显示变量及其值但是当我调用变量时它不会显示它,即使我调用变量愚蠢的{{ dumb(title) }}
它告诉我是NULL。谁能帮我理解错误是什么?
块:onyx_experiencia.php
/**
* Provides a 'Test' Block.
*
* @Block(
* id = "onyx_experiencia",
* admin_label = @Translation("Servicios OnyxGroup"),
* category = @Translation("Servicios OnyxGroup"),
* )
*/
class onyx_experiencia extends BlockBase implements BlockPluginInterface {
/**
* {@inheritdoc}
*/
public function build() {
$title = 'TestTitle34';
$desc = 'Test text 24';
$test_array = array(
'#title' => $title,
'#description' => $desc
);
return $test_array;
}
block.module : onyx_experiencia.module
<?php
/**
* Implements hook_theme().
*/
function onyx_experiencia_theme($existing, $type, $theme, $path) {
return array(
'block__serviciosonyxgroup' => array(
'template' => 'block--serviciosonyxgroup',
'render element' => 'elements',
'variables' => array(
'title' => 'TitleTest',
'description' => 'DescriptionTest'
),
),
);
}
树枝文件:块--serviciosonyxgroup.html.twig
{#
/**
* @file
* Profile for onyx_experiencia block.
*/
#}
<h3>Featured Events</h3>
<p>Test: {{ title }} </p>
<p>Test: {{ description }} </p>
<ol>
{% for key, value in _context %}
<li>{{ key }}</li>
{% endfor %}
</ol>
{{ dump(content) }}
更新不同的方式仍然无法正常工作