0

I have the code below and I need to pass an html element (anchor) as shown. I have tried using filters like raw and escape but it always prints out the html element as regular text. I also tried setting a new variable that contains the same string text and passed that to testLink and then applied filters to it, but same result. Any ideas how to tackle this problem?

{% include 'example.html.twig' with {'testLink': 'Hurry, <a href="#">Click me NOW</a>'} %}
4
  • What does your included template look like? Commented Dec 28, 2015 at 22:52
  • @xabbuh it is plain html <div class="col-md-4"><p>{{ testLink }}</p></div> Commented Dec 28, 2015 at 23:06
  • Where did you use the raw filter? In the included template or when including it? Commented Dec 28, 2015 at 23:09
  • @xabbuh I tried this ... with {'testLink': 'Hurry, <a href="#">Click me NOW</a>'|raw} Commented Dec 28, 2015 at 23:25

1 Answer 1

2

You cannot handle your problem in the template that is including the example.html.twig template as autoescaping will step in when the passed value is displayed in the included template. Instead, you will have to use the raw filter in example.html.twig (be careful with that solution though as the template is probably used in other places too which might not be safe).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.