I tring to use macros
{%- macro button(link,text) %}
<a href='{{link}}' class='btn btn-default'>{{text}}</a>
{%- endmacro %}
{{ button('link','te<b>st</b>') }}
It works perfect. But if I try to move forward and write
{%- macro button1(link,text) %}
<a href='{{link}}' class='btn btn-default'>{{text|e}}</a>
{%- endmacro %}
{{ button1('link','te<b>st</b>') }}
I have error. Because no $this is defined inside macros function. WTF
Volt generates following code
function vmacro_button1 ($__p) { /* check args */
echo $this->escaper->escapeHtml($text); // $this is not defined here
}
// ...
echo vmacro_button1(array('link', 'te<b>st</b>'));
Possible construction to define $this in function could look like
global $g_vmacro_button1; $g_vmacro_button1=function($__p) { /* check args */
echo $this->escaper->escapeHtml($text);
};
Closure::bind($g_vmacro_button1,$this);
function vmacro_button1($__p) { global $g_vmacro_button1; $g_vmacro_button1($__p); }
// ...
echo vmacro_button1(array('link', 'te<b>st</b>'));
The question is how to change the former macros into latter?