web-mode icon indicating copy to clipboard operation
web-mode copied to clipboard

<TMPL_ELSE> support from Perl HTML template

Open kjohnson0451 opened this issue 2 years ago • 3 comments

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.

kjohnson0451 avatar May 04 '22 21:05 kjohnson0451

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.

kjohnson0451 avatar May 13 '22 18:05 kjohnson0451

what the file extension for this kind of templates ?

fxbois avatar May 24 '22 19:05 fxbois

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.

kjohnson0451 avatar Jun 01 '22 13:06 kjohnson0451

the last commit brings compatibility with perl templates

fxbois avatar Aug 19 '22 11:08 fxbois

Sweet, works like a charm. Thanks! You made this dev's life a little easier.

kjohnson0451 avatar Aug 20 '22 15:08 kjohnson0451