-
Notifications
You must be signed in to change notification settings - Fork 2
Syntax Partials
Partial tags are the "import" mechanism of Mustache. They are useful for breaking up a large markup file into multiple smaller files.
Partial tags are opened with the {{> token and closed with the }} token. The content within the tags constitutes the tag name and is used to perform lookups into the data set. The tag name cannot include whitespace except as prefix or postfix. All other characters are valid tag names.
Partial tags obey the Change Delimiter command.
The following line of JavaScript code:
Mustache.to_html('{{>a_partial}}', { bugs: 'bunny' }, { a_partial: '{{bugs}}' });
Will output the following result:
'bunny'
Whitespaces are only okay as prefixes and postfixes:
{{> bugs }}
Currently, partials also act as implicit sections. That is, if the data set has a key with the same value as the tag name, that value will be used as a subsequent sub-context for future key lookups. In the Mustache spec, partials do not act as implicit sections and in the future this behaviour will be dropped to comply.
In this implementation, if a partial does not exist as a key in the partials argument to Mustache.to_html or Mustache.compile, then the parser will throw a MustacheError. The Mustache Spec says that this case should be treated as a empty string substitution. This variation will most likely be captured by a pragma in the future.