This is a neat little HTML preprocessor from Giuseppe Gurgone. It has very few features, but one of them is HTML includes, which is something I continue to be baffled that HTML doesn’t support natively. There are loads of ways to handle it. I think it’s silly that it’s been consistently needed for decades and HTML could evolve to support it but hasn’t. So anyway, enter another option for handling it.
What is extra neat is that it’s not just includes, but templating with includes in a really clean way. If this was Nunjucks, they solve that by creating a template.njk
like…
{% block header %}
This is the default (overridable) header.
{% endblock %}
<footer>
{% block footer %}
This is the default (overridable) footer.
{% endblock %}
</footer>
And then your actual pages use that template like…
{% extends "parent.html" %}
{% block footer %}
Special footer for this page.
{% endblock %}
In xm, the syntax stays HTML-y, which is nice. So this template.html
…
<slot name="header"></slot>
<footer>
<slot name="footer"></slot>
</footer>
…gets used on a page like this:
<import src="template.html">
<fill name="header">Custom Header</fill>
<fill name="footer">
<p>Custom footer</p>
</fill>
</import>
Very clean. The additional fact that you can arbitrarily chuck a <markdown>
tag anywhere you want and use Markdown within it is extra handy.
There are a suite of tools under the pHtml name that are able to do this along with a couple other neat features.
It’s all HTML focused instead of JS.
https://github.com/phtmlorg/phtml#readme
I really enjoy using it and it’s plugins.
I like this a lot better than nunjucks. If one were to use this with Gulp, would they have to use this https://github.com/posthtml/gulp-posthtml since the project is technically a posthtml plugin?
hi Jakob, check this GitHub issue out https://github.com/giuseppeg/xm/issues/10