将img标签添加到由php函数呈现的按钮

时间:2017-12-05 16:59:23

标签: php symfony twig

我试图将<img>标签添加到由php函数创建/呈现的按钮(按钮内)。

在这个功能中,最后,我有这个:

return $environment->render('WizardBundle:Participation:ssa.html.twig', $parameters);

ssa.html.twig有:

{% if url is defined %}
    <a href="{{ url }}" {{ attributes|raw }}><img src="{{ asset(assetsPath ~ '/images/image.png') }}">{{ label|trans({}, 'wizard') }}</a>
{% else %}
    <p>{{ label }}</p>
{% endif %}

我尝试在<a>内添加标记,但没有显示任何内容。 我是否需要修改该php函数中的任何内容(如果需要可以发布)?

1 个答案:

答案 0 :(得分:0)

这对我来说很好用:

$parameters = [
    'url' => 'http://google.es',
    'attributes' => 'target="_blank"',
    'label' => 'button',
    'assetsPath' => ''
];
模板上的

{% if url is defined %}
    <a href="{{ url }}" {{ attributes|raw }}>
        <button><img src="{{ asset(assetsPath ~ '/images/image.png') }}"> {{ label }}</a></button>
    </a>
{% else %}
    <p>{{ label }}</p>
{% endif %}

如果不能为您工作,您可以填写完整的代码吗?