Skip to content

Instantly share code, notes, and snippets.

@MacDada

MacDada/template.twig

Last active Dec 6, 2016
Embed
What would you like to do?
{# what is the proper way to escape var in url path in html in twig? #}
{# method A #}
<a href="/foo/{{ bar }}">Link</a>
{# method B #}
<a href="/foo/{{ bar|e('url') }}">Link</a>
{# method C #}
<a href="/foo/{{ bar|url_encode }}">Link</a>
{# method D #}
<a href="/foo/{{ bar|url_encode(true) }}">Link</a>
{# other? #}
@MacDada

This comment has been minimized.

Copy link
Owner Author

@MacDada MacDada commented Dec 6, 2016

  • A doesn't escape for url
  • B and C both use rawurlencode()
  • B wins as it does the job and is semantically superior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment