gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.9k stars 7.54k forks source link

Proposal: Plush templating #6095

Closed lucperkins closed 4 years ago

lucperkins commented 5 years ago

Over time, I've learned to like Go's native templating system but I do occasionally miss the "scripting language" feel of templating systems like Mustache and Liquid. It would be good if Hugo had a roughly analogous counterpart. This would ease the transition to Hugo for people coming from tools like Jekyll and Middleman and might even draw in some people like me who have become skilled with Go templating by accident.

Enter Plush, the templating system from the people who make the Buffalo web framework. It provides a templating syntax highly reminiscent—though not any kind of direct copy—of Liquid-style engines and even goes beyond them by providing things like inline functions. Here's an example (from Plush's README):

<%= if (names && len(names) > 0) { %>
<ul>
  <%= for (n) in names { %>
  <li><%= capitalize(n) %></li>
  <% } %>
</ul>
<% } else { %>
<h1>Sorry, no names. :(</h1>
<% } %>

The equivalent using Go templates (off the top of my head):

{{ if and .names (gt len(.names) 0) }}
<ul>
  {{ range .names }}
  <li>{{ . | uppere }}</li>
  {{ end }}
</ul>
{{ else }}
<h1>Sorry, no names. :(</h1>
{{ end }}

Personally, I've come to prefer the latter over time, but it took me years to get there. The former has the potential to draw in new users and open up broad new horizons.

If I could get a few pointers on how to accomplish this I'm happy to do the work myself. I've poked around in the tpl directory but I'm still not quite sure how to make it happen. It's pretty clear how an HTML engine à la Ace and Amber work but the pre-HTML engine is less clear.

bep commented 5 years ago

but I do occasionally miss the "scripting language"

I think an addition like this needs something bigger than to just satisfy a "craving".

We have Ace and Amber, but they compile to Go templates, so much easier to integrate. I don't know the Buffalo people good enough to understand if this is really great or not, but I have lots of questions:

So, it looks cool, and I hate to be the negative one. I expect a response in the line of "people could still use this for stuff without Hugo Pipes etc.", and you would probably be right, but even if we document those shortcomings, we would have plenty of support questions asking why "this and that fails".

lucperkins commented 5 years ago

@bep Those are 1000% valid concerns, so there's no harm in being the "negative one" here. I'll respond to your issues one by one:

In general, I concede that this is probably a "will not implement" at least for the time being, as I suspect that the necessary conditions aren't yet in place. But I'll keep tabs on it. Something like Mustache might be more realistic.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.