Sequential template language with extension?

I like the minimal mustache pattern programming languages ​​- currently I use mustache and icanhasmustache, but I have also checked handlebars and hogan .

However, I have a need for extends functionality to allow a child to refer to a specific parent template. I cannot find documentation on how extensions are implemented in any of the above, but I saw (from random githib gists) that other people do this.

Note I know about the existence of include (sometimes called partials), however, it seems to the parent a reference to a specific child. This is the opposite of what I am looking for - the child template in this case is the real "base" document, and the parent is just random, so I want the child to control the relationship.

+4
source share
3 answers

Twitter implementation of Mustache, Hogan seems to now support inheritance.

See recent commit: Hogan 3. Add template inheritance ...

+2
source

2016 answer :

If you use express, the layout middleware takes a layout parameter, which may be useful.

 res.render('page', { layout: 'mylayout.jade' }) 

original answer : very few JS libraries implement functionality like extends.

  • Nun is a very mustache, but only a server (and is no longer supported)
  • Swig is spread, but not very mustache.
  • Jade expands and works in the browser, but not a mustache, such as

I settled on Dust.JS , since it uses mustache-like sections, works on the client and server, and supports overlapping blocks on the parent from the child, giving effective support.

See dust documentation, section "Blocks and embedded particles":

 {>base_template/} {<title} Child Title {/title} {<main} Child Content {/main} 

Overriding the 'title' and 'main' sections from the parent template, preserving the surrounding content.

+8
source

I am studying Nunjucks, which promises fixes some problems and also supports inheritance.

EDIT:

I really took Nunjucks, it is pretty durable. One limitation I came across is that you cannot specify multiple folders for pre-compilation, but I wrote a script to allow this.

+5
source

Source: https://habr.com/ru/post/1400193/


All Articles