Tuesday, May 30, 2023
HomeiOS DevelopmentThe way forward for Leaf and Tau

The way forward for Leaf and Tau

Which template engine ought to I select for Vapor? What is the distinction between Leaf and Tau? Let me clarify every little thing.



To begin with, if you do not know, the Leaf 4 launch accommodates some main syntactical modifications in comparison with the earlier model. Curly brackets have been changed with the brand new #finish prefix syntax.

It is a main step ahead, but in addition a breaking change, meaning it’s important to improve your at the moment current Leaf 3 codebase, in any other case your templates will not work. The opposite main change is expounded to template inheritance. The brand new prolong, export and import key phrases changed the earlier embed and set key phrases, once more.

So right me if I am incorrect, however this enchancment is like taking a step backward, as a result of in Leaf 2, we had roughly the identical template inheritance API features (import, export, prolong, and embed). I suppose that this variation could be complicated for some individuals who have been already acquainted with the 2nd or the third model of Leaf. (I used to be stunned once I noticed these modifications.) 😐

I do not wish to criticize this resolution, however these modifications do not vital deserve a serious model quantity. It is not an enormous enchancment from a developer (end-user) perspective. The one factor what modified with Leaf 4.0.0 is that we builders have to vary our codebase to make issues work once more, however we have gained nearly zero new options, that I would count on from a serious launch.

I used to be very unhappy about this and I can think about that this will make server aspect Swift builders fairly upset. I’ve already missed numerous options from Leaf, that I would count on from a contemporary template engine. Simply check out mustache or handlebars, they’re in fact older, nevertheless it’s price to say that they’ve some far more superior options, that you just nonetheless cannot do in Leaf. 😢

Now, in the course of the 4.0.0 improvement an attention-grabbing factor occurred with Leaf…


There was a brand new department referred to as Tau (means rebirth) created and maintained by @tdotclare. I jumped the prepare and began to make use of this experimental department as a substitute of the principle / dev.

We additionally began to speak quite a bit with tdotclare, since there have been some points, particularly at first, however lastly I’ve discovered somebody on Vapor’s discord who I may ask about Leaf. He helped me lots and I am extraordinarily grateful, as a result of with out him, the template layer of Feather CMS would not be such an incredible (modular, reusable, extensible) system. 🙏

Lengthy story quick, tdotclare applied a lot of nice new options for Leaf Tau, the entire system began to appear like as an actual template engine, not simply one thing that you might use to switch key-based variables in a really lengthy output string. (Pardon me, however that is the case with Leaf.) 🙈

We had a imaginative and prescient about the way forward for Tau, the place you might differentiate sorts, create new language components and particular extensions (features, strategies, blocks, contexts) for the duty you have to remedy, in a protected and straightforward manner. Tau already has all these goodies and much more.

You possibly can outline variables and constants, and the brand new template hierarchy system appears to be extra logical and future proof than another earlier variants of the template inheritance APIs. Lastly, after numerous hours of conversations, feedbacks, testing, and bug squashing, the Tau options have been merged to the principle department and launched below the 4.0.0-tau.1 tag.

If you wish to preserve utilizing Tau, it’s best to pin your Swift dependency variations to:
.package deal(url: "https://github.com/vapor/leaf", .actual("4.0.0-tau.1")),
.package deal(url: "https://github.com/vapor/leaf-kit", .actual("1.0.0-tau.1.1")),

Sadly, the Vapor core crew determined to revert these modifications shortly after the Tau launch with no detailed rationalization. So far as I do know the principle purpose was that the core crew needs to maintain Leaf as a “easy” template engine. Do not get me incorrect, I am effective with that call, however then it was undoubtedly a mistake to formally launch Tau and shortly after take away it similar to that. 😕

The long run

So this is what I used to be interested by this complete subject in the previous few months.

Leaf 4.x

I’ve all the time felt like these new Tau options are manner too good to easily drop them, simply to go along with Leaf. Plus what does the time period “easy” means? Can I count on something new in Leaf or is it going to be solely bug fixes solely to any extent further? Is the longer term vivid for Leaf or ought to I merely drop it? 💧

Nicely, sure. I am not going to make use of Leaf once more.

If you’re planning to construct a brand new mission and also you want a dependable, quick, dynamic template engine with a simply very primary (restricted) function set, then it’s best to think about using Leaf. 🍃

Area Particular Languages

These days everyone seems to be into DSL’s (SwiftUI), so why not use a DSL library, equivalent to HTMLKit or Plot as a substitute of Leaf? If the template engine will not permit me to do extra sooner or later then a DSL could be a manner more sensible choice. It may very well be extra protected and performant, however in fact we might sacrifice the dynamic nature (you all the time should recompile the whole server code after one thing modifications), however nonetheless, primarily based on the circumstances, I can solely consider this answer as a greater various.

If you happen to do not wish to dynamically replace templates and also you’re effective with the “static website generator” method, then I would counsel to make use of a Area Particular Language primarily based template engine.


It’s a dynamic template engine with a really wealthy function set, that you should use to construct extra complicated templates. Since Tau is derived from Leaf it implies that the syntax may be very related, so the official Leaf documentation covers just about every little thing that it’s important to learn about it, plus I have already got some good tutorials on my website about utilizing the brand new options of Tau.

Primarily based on my expertise, I will follow “Tau”.

It is best to know, that the 4.0.0-tau.1 launch below the vapor/leaf repository may be very steady, so you should use that tag for now if you wish to give an opportunity to Tau.

It’s price to say that Tau can be re-released afterward in a separate repository below a model new identify. Sadly, I can not give a precise schedule for the transition course of simply but. Hopefully this manner we will keep away from additional confusions and builders can decide the suitable software for the job.

The Vapor core crew and the authors of Leaf are doing an incredible job. This submit shouldn’t be meant to hurt them in any manner, however I simply wished to supply some actual rationalization for everybody who was asking me in regards to the present standing of Leaf and Tau. Thanks for understanding this. 🙏



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments