Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jakedohm
Created November 7, 2019 21:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakedohm/39190ec533e69e83b9cee4bdf3898a60 to your computer and use it in GitHub Desktop.
Save jakedohm/39190ec533e69e83b9cee4bdf3898a60 to your computer and use it in GitHub Desktop.
{# Bad: Messy and Hard to Follow #}
{% if link %}
<a href="/recipes/cookies">
{% endif %}
<span>Cookies</span>
{% if link %}
</a>
{% endif %}
{# Good: Clean & Clear #}
{% set content %}
<span>Cookies</span>
{% endset %}
{% if link %}
<a href="/recipes/cookies">
{{ content }}
</a>
{% else %}
{{ content }}
{% endif %}
@clarknelson
Copy link

beautiful thanks, i've tried to solve this with a ternary before but this is much better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment