diff --git a/README.md b/README.md index 4051bed..adf8190 100644 --- a/README.md +++ b/README.md @@ -113,3 +113,36 @@ The following sequence context transforms are available - index: Returns the index of the element within the sequence - odd: Returns if the index of the element is odd - even: Returns if the index of the element is even + +### Template inheritance + +Template inheritance is not part of the Mustache spec yet but it is a commonly implemented feature. Template inheritance allows you to override elements of an included partial. It allows you to create a base page template and override elements of it with your page content. A partial that includes overriding elements is indicated with a `{{`. This is a section tag so needs a ending tag as well. Inside the section the tagged sections to override are added using the syntax `{{$tag}}contents{{/tag}}`. If your template and partial were as follows +``` +{{! mypage.mustache }} +{{My page title{{/head}} +{{$body}}Hello world{{/body}} +{{/base}} +``` +``` +{{! base.mustache }} + + +{{$head}}{{/head}} + + +{{$body}}Default text{{/body}} + + +``` +You would get the following output when rendering `mypage.mustache`. +``` + + +My page title + + +Hello world + +``` +Note the `{{$head}}` section in `base.mustache` is replaced with the `{{$head}}` section included inside the `{{