posthtml-expressions
posthtml-expressions copied to clipboard
[feat]: with template
<each loop="item in [['/', 'Home'], ['/about', 'About'], ['/contact', 'Contact']]">
<a class="mdl-navigation__link" href="{{ item[0] }}">{{ item[1] }}</a>
</each>
use template
import template from 'foo.html';
document.querySelector('#ex').innerHTML = template({
List: [['/', 'Home'], ['/about', 'About'], ['/contact', 'Contact']]
});
<each loop="item in ${ _.List }">
<a class="mdl-navigation__link" href="{{ item[0] }}">{{ item[1] }}</a>
</each>
Output:
<each loop="item in /, Home, /about, About, /contact, Contact">
<a class="mdl-navigation__link" href="{{ item[0] }}">{{ item[1] }}</a>
</each>
Posthtml's templating method will not generate client-side templates with posthtml-expressions, it is only compatible with interpolated strings like <p>Hello ${planet}</p>.
Currently the only way to get client-side templates with plugins is to have the code generator output a function, which is only possible at the moment using the reshape version. Although hopefully this functionality will also be coming to posthtml soon!
duplicate of #54