llanato llanato - 7 months ago 62
Twig Question

Twig: Variable in format function

I'm passing in a string to

which is:

Not a member? %sCreate a Free account%s.

And also
which has a value of:


Due to the first format variable having HTML I've also passed in the
option for this element.

<p class="highlight">
{{ login_create_account_label | format('<a href="{{ login_create_account_url }}">', '</a>') | raw }}

I've been unable to get it to output as I want it to.

Expected (Source HTML):

<p class="highlight">
Not a member? <a href="http://localhost/register/">Create a Free account</a>.

What I'm getting:

<p class="highlight">Not a member? 0Create a FREE account</a>.</p>


Twig string manipulation can be a little tricky as there's a bunch of tools available.

Instead of outputting the variable using the output ( {{...}} ) syntax, consider converting your operand to a string using the '~' operator. You can read more about it here.


<p class="highlight">
{{ login_create_account_label|format('<a href="' ~ login_create_account_url ~ '">', '</a>')|raw }}