web-mode
web-mode copied to clipboard
<TMPL_ELSE> support from Perl HTML template
Another request to support syntax from Perl HTML template https://metacpan.org/pod/HTML::Template
A <TMPL_ELSE>
's indent should decrement. Then the lines after <TMPL_ELSE>
should increment so it matches the usual indentation of the <TMPL_IF>
's children. And it probably doesn't need to check to make sure the parent tag is <TMPL_IF>
, that's incidental.
Like so.
<TMPL_IF NAME="WHAT">
YEAH
<TMPL_ELSE>
OKAY
</TMPL_IF>
This is how it currently works
<TMPL_IF NAME="WHAT">
YEAH
<TMPL_ELSE>
OKAY
</TMPL_ELSE>
</TMPL_IF>
If you can't get around to it, some pointers on how to do it myself would be appreciated. I've been trying to comprehend web-mode-indent-line
but there's a lot to unpack.
I can see there are other patterns within web-mode that deal with this kind of thing. In Django mode, it handles this syntax perfectly well:
<ul>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% else %}
<li><em>no user found</em></li>
{% endfor %}
</ul>
But from what I can tell, this {% for ... %}
is a "block" as defined by Django mode. And {% else %}
isn't a "beginning" or "end", but "inside". Which is great, but...
What makes <TMPL_ELSE>
really tricky to implement is that it's an HTML tag, rather than a block. And there's no mechanism to classify a tag as "inside". All this helpful block functionality is not available to me, all because this Perl module uses a template language that sort of piggy-backs on top of HTML syntax.
what the file extension for this kind of templates ?
Sorry for the delay. By default, those files use the .tmpl
extension. You can see the link in the OP has an example test.tmpl
.
But I hesitate to suggest you to use that. It'd be better to use something else and I just make a hot-edit/separate branch where I'm using my internal extension. Maybe you could use .ptmpl
or something if you end up tackling this.
the last commit brings compatibility with perl templates
Sweet, works like a charm. Thanks! You made this dev's life a little easier.