Skip to content

Instantly share code, notes, and snippets.

@MacDada
Last active December 6, 2016 21:32
Show Gist options
  • Save MacDada/d677277d4d184541f0fdfb17a38ad1de to your computer and use it in GitHub Desktop.
Save MacDada/d677277d4d184541f0fdfb17a38ad1de to your computer and use it in GitHub Desktop.
{# 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
Copy link
Author

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