Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Dynamic Names #1

Merged
merged 10 commits into from Sep 17, 2022
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion man/mustache.5.ron
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ replaced with a value, some nothing, and others a series of
values. This document explains the different types of Mustache tags.

The Mustache language has a [formal specification][spec]. The current
manpage reflects version 1.2.1 of the specification, including the
manpage reflects version 1.3.0 of the specification, including the
official-but-optional extensions for lambdas and inheritance.

[spec]: https://github.com/mustache/spec
Expand Down Expand Up @@ -411,6 +411,36 @@ Can be thought of as a single, expanded template:
{{/names}}


**Dynamic Names**

Partials can be loaded dynamically at runtime using Dynamic Names; an
**optional** part of the Mustache specification which allows to dynamically
determine a tag's content at runtime.

Dynamic Names consists of an asterisk, followed by a dotted name which follows
the same notation and the same resolution as in an variable tag. That is
`{{>*dynamic}}`. It can be thought as the following **hypothetical** tag
(which is **not allowed**!): `{{>{{dynamic}}}}`.

Templates:

main.mustache:
Hello {{>*dynamic}}

world.template:
everyone!

Hash:

{
"dynamic": "world"
}

Output:

Hello everyone!
jgonggrijp marked this conversation as resolved.
Show resolved Hide resolved


### Blocks

A block begins with a dollar and ends with a slash. That is, `{{$title}}`
Expand Down Expand Up @@ -484,6 +514,35 @@ Output, assuming the `article.mustache` from before:
<h1>Yesterday</h1>
<p>Nothing special happened.</p>

**Dynamic Names**

Some mustache implementations may allow the use of Dynamic Names in
parent tags, similar to dynamic names in partials. Here's an example of
how Dynamic Names in parent tags work.

Templates:

{{!normal.mustache}}
{{$text}}Here goes nothing.{{/text}}

{{!bold.mustache}}
<b>{{$text}}Here also goes nothing but it's bold.{{/text}}</b>

{{!dynamic.mustache}}
{{<*dynamic}}
{{$text}}Hello World!{{/text}}
{{/*dynamic}}

Hash:

{
"dynamic": "bold"
}

Output:

<b>Hello World!</b>


### Set Delimiter

Expand Down