Home:ALL Converter>twig macros argument is a combination of a string and a variable

twig macros argument is a combination of a string and a variable

Ask Time:2013-09-28T23:22:16         Author:Milio

Json Formatter

Hello I'm having problems with a macro.

in macros.html.twig

{% macro panel_header(title) %}
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">{{ title|escape('html') }}
    </div>
{% endmacro %}

in profile.show.html.twig

{% import "macros.html.twig" as macros %}
{{ macros.panel_header("hello"  {{profile.name}} ) }}

Above example doesn't work because it asks that arguments are separated by a comma

{{ macros.panel_header("hello  {{profile.name}}" ) }}

This outputs "hello {{profile.name}} which makes sense ofcourse

So my question is how can i add a string and a variable as a single argument to a macro?

Author:Milio,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19068486/twig-macros-argument-is-a-combination-of-a-string-and-a-variable
kachar :

String interpolation (#{expression}) allows any valid expression to appear within a double-quoted string. The result of evaluating that expression is inserted into the string:\n\n{{ \"foo #{bar} baz\" }}\n{{ \"foo #{1 + 2} baz\" }}\n\n{{ macros.panel_header(\"hello #{profile.name}\") }}\n\n\nString interpolation was added in Twig 1.5",
2013-11-06T02:41:18
yy