## Explorations in re-using Twig templates for the front-end - Eirik Morland - Developer at Ny Media - [eiriksm@github](https://github.com/eiriksm/) - [eiriksm@drupal.org](https://www.drupal.org/u/eiriksm) - [@orkj](https://twitter.com/orkj) - Background: Masters in art criticism - Beer geek and animated gif enthusiast (gif ratio 36.1%)
## What we will cover - Part 1: What is the story behind getting where we are now? - Part 2: What is the current state of how we can do this? - Part 3: What are some usecases for implementing it? - Part 4: What are some bad examples of template-sharing code-bases? - Part 5: Hacks, tips and tricks
## What we will cover - Chapter 1: Art - Chapter 2: Magic - Chapter 3: Heroes - Chapter 4: Villains - Chapter 5: Dark sorcery
## Chapter 1: Art

                    <marquee>
                      <blink><?php print $page_title; ?></blink>
                    </marquee>
                  

                      <marquee>
                        <blink>{{ page_title }}</blink>
                      </marquee>
                    

page.html.twig


                    <h2>{{ title }}</h2>
                    <div id="app"></div>
                  

app.js

                    React.render(
                      <App />,
                      document.getElementById('app')
                    );
                  
## Chapter 2: Magic
### Twig.js >...a pure JavaScript implementation of the Twig PHP templating language
## Chapter 3: Heroes
## Chapter 4: Villains
## Cost/value
- Twig.js minified is 83K - React.js + React DOM minified is 46kb
## Chapter 5: Dark sorcery
## underscore.js
```js var compiled = _.template("hello: <%= name %>"); compiled({name: 'moe'}); => "hello: moe" ```
``` var templateSettings = { interpolate: /\{\{(.+?)\}\}/g }; ```
``` var compiled = _.template("hello: {{ name }}", templateSettings); compiled({name: 'moe'}); => "hello: moe" ```
## Summary - The art history of the village of the web is beautiful and constantly evolving - Some people in this village are heroes, but they might not be everyone’s heroes - Sometimes there are no wizards that can sprinkle magic dust over your application and give you the bliss of sharing templates - You can use dark sorcery, but only if you dare
## Resources - [Twig website](https://twig.symfony.com/) - [Twig.js website](https://github.com/twigjs/twig.js) - [Twig.js module for Drupal 8.](https://www.drupal.org/project/twigjs) - [https://eiriksm.github.io/twig-and-twigjs-talk/ (slides)](https://eiriksm.github.io/twig-and-twigjs-talk/)