Skip to content
This repository has been archived by the owner on Apr 7, 2019. It is now read-only.

show unique twig features #4

Merged
merged 5 commits into from
Apr 12, 2016
Merged

show unique twig features #4

merged 5 commits into from
Apr 12, 2016

Conversation

EvanLovely
Copy link
Member

This shows off some unique Twig features that really show it's power over Mustache: Template Inheritance using extends and blocks really help out the Templates, and a macro helps with forms in this pull request.

@dmolsen dmolsen merged commit 3720eda into pattern-lab:master Apr 12, 2016
@TxHawks
Copy link
Contributor

TxHawks commented Apr 12, 2016

It may be worth also including an example of embed. To me, this is where Twig really shines compared with Mustache.

There isn't currently a pattern that is complex enough for showing the power of embed, but it can be used for extending individual UI patterns within pages.

So, as a simplified example, say we use the card UI pattern across several components that share a similar html "shell", but vary in their internal html, we could do:

{#- card.twig -#}
<article class=card {{ extra_classes }}>
  {% block card_body -%}
  {%- endblock %}

  <footer class=card__footer>
    {% block card_footer -%}
    {%- endblock %}
  </footer>
</article>

and then:

{#- some-organism.twig -#}
{% embed "card.twig" with {extra_classes: 'card--b  some-component' %}
  {% block card_body -%}
    include('molecule-a')
    include('molecule-b')
  {%- endblock %}
  {% block card_footer -%}
    include('molecule-c')
  {%- endblock %} 
{% endembed %}

Of course, this is a very simple example, but with more complex UI patterns, this can greatly improve DRYness

@dmolsen
Copy link
Member

dmolsen commented Apr 12, 2016

@EvanLovely -

I don't think we need a pure 1-to-1 with the Mustache demo if there is something special like this that can't really be done in that template language. Feel free to include if you agree.

@EvanLovely
Copy link
Member Author

I think this would be awesome to include as I can totally see the use case! I've made an issue to track it: #6. @TxHawks - hit it up if you want! I might get to it after a bit, but my initial goal was to get this repo further than it's original minimal state and then to show off a couple of the features that demonstrates why Twig could work better than Mustache for some people. Thanks for the idea!!

@EvanLovely EvanLovely deleted the feature/show-unique-twig-features branch April 12, 2016 21:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants