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 3 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
39 changes: 38 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,37 @@ Can be thought of as a single, expanded template:
{{/names}}


**Dynamic Names**

Partials can be loaded dynamically at runtime using Dynamic Names; an
**optional** special notation which allows to dynamically determine a tag's
This conversation was marked as resolved.
Show resolved Hide resolved
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 Interpolation tag. That is
This conversation was marked as resolved.
Show resolved Hide resolved
`{{>*dynamic}}`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps compare this to the hypothetical {{>{{dynamic}}}} to further clarify what it does.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that including wrong examples may be confusing

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are quite right that it could be confusing. Very friendly of you to go with it anyway! I still think the hypothetical nested tag can also serve to clarify the concept, but please feel absolutely welcome to add an additional remark, something like (which is not allowed!) just before or after the forbidden example.


Failed resolution of the dynamic name SHOULD result in nothing being rendered.
This conversation was marked as resolved.
Show resolved Hide resolved

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 All @@ -426,6 +457,9 @@ Blocks could be thought of as template parameters or as inline partials
that may be passed to another template. They are part of the optional
inheritance extension.

If you want to dynamically load a partial you may want to take a look at Dynamic
Names.

jgonggrijp marked this conversation as resolved.
Show resolved Hide resolved
Template `article.mustache`:

<h1>{{$title}}The News of Today{{/title}}</h1>
Expand All @@ -451,6 +485,9 @@ blocks of the other template.
Blocks within a parent can again be overridden by another including
template. Other content within a parent is ignored, like comments.

If you want to dynamically load a partial you may want to take a look at Dynamic
Names.

Template:

{{<article}}
Expand Down