r/ProgrammingLanguages • • Jun 13 '26

Blog post Language Design of a new template language

https://pinc-official.leaflet.pub/3mo3nsla6z22u

I have been working on a new template language in my free time. Its trying to solve some problems I have with other template languages which are outlined in the post.

Its not released / ready yet, but I am looking for some feedback :)

17 Upvotes

11 comments sorted by

View all comments

Show parent comment

2

u/t_ewert Jun 14 '26

For a practical templating language, personally I've pretty much decided that if there's going to be any computation, I just want it to be expressed in the host programming language

For complex logic / data transformation I agree 100%. But in my experience there are still a lot of small data transformation tasks that fit more in the template language itself.
In the end I think it comes down to personal taste of the developer and the task at hand 😄

I don't really like the "Slot" idea at all, including in other template frameworks. [...]
You can just have function calls, with named arguments.

I also think the slot could be replaced by something better. And yes, functions are really great 😄
I am curious how you would imagine the function calls as a slot replacement look like. Would you mind giving an example? 🙂

1

u/liquidivy Jun 15 '26

I am curious how you would imagine the function calls as a slot replacement look like. Would you mind giving an example?

There's not much to the idea. Whatever goes in the "slot" becomes a regular boring argument instead. I guess there's a couple different ways you might want to pass template content to a function. You might want to pass them as functions, and have the component call them (or maybe not), rather than calling them and passing in the rendered result (or even do a weird f-expr thing that amounts to another way to pass code instead of results).

I guess your MediaText would look a bit like: MediaText(text="something profound", media=Image(...), links=[Button(...), Link(...)]).

Also check out how Phoenix/Elixir does its Heex templates. I wasn't able to find a really good intro source about it, but it's a slightly different approach that I really like for how functional it is (in all the clever meanings). (This seems like the in-sequence tutorial)[https://phoenix.hexdocs.pm/components.html#function-components]. The syntax might be a lot to jump into, YMMV.