From 71f579fafa72bd7f824a817422e16cfb9f2787b4 Mon Sep 17 00:00:00 2001 From: Luke Blaney Date: Mon, 13 May 2024 23:43:01 +0100 Subject: [PATCH] add dynamic name example to README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index ea74fc8..5616bfc 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,29 @@ Mustache.render(template, view, { }); ``` +Partials can have dynamic names, which begin with `*`. In this case, a value is read from the context and the partial with that value is used. + +For example, this template and partial: + + base.mustache: +

Message of the Day

+ {{> *dayOfWeek}} + + thursday.mustache: + This must be Thursday. I never could get the hang of Thursdays. + +When loaded with the context: +```json +{ + "dayOfWeek": "thursday" +} +``` +will be expanded to: +```html +

Message of the Day

+ This must be Thursday. I never could get the hang of Thursdays. +``` + ### Custom Delimiters Custom delimiters can be used in place of `{{` and `}}` by setting the new values in JavaScript or in templates.