On May 11, 2008, in General, by Neil Stevens

Got it done. I can’t quite do Django’s inheritance without a bunch of work, but I got something done right away.

In Django, the parent template puts in block tags which may or may not contain default values. The child templates then also have the same block tags containing their preferred values. The tags then go on down the line neatly. The child templates also declare their parent at the top of the file.

In Liquid I leveraged the existing capture and include tags to get close, along with creating my own default tag based on capture. The base template uses default, declaring where the common blocks go, including default text where appropriate. Inheriting templates use capture to override those where wanted. It works, but it has an aesthetic glitch: because I’m just using context variable assignments, the inheritance is ‘declared’ by using an include at the bottom of the child template file.

So it’s not perfectly like Django, but I can certainly use it.


Comments are closed.

Nima Jooyandeh facts.