Skip to content

Conversation

@vrugtehagel
Copy link
Contributor

Allows passing data as a variable, rather than an object literal, both for the {{ include }} tag and {{ layout }} tag.

Since paths can include JavaScript themselves, as in, for example, {{ include "./template" + ext }}, this requires a bit of care. This solution decides whether the last "word" in the tag is a data argument by looking at what is in front of it; if it is a quote character of any kind, or a word character, followed by some whitespace, then the last name token is a data variable.

Naturally, there are edge cases. Currently this does not allow for passing something like data.foo or data[0], but presumably can be extended to do so.

Resolves #163.

Allows passing data as a variable, rather than an object literal, both
for the `{{ include }}` tag and `{{ layout }}` tag.

Since paths can include JavaScript themselves, as in, for example,
`{{ include "./template" + ext }}`, this requires a bit of care. This
solution decides whether the last "word" in the tag is a data argument
by looking at what is in front of it; if it is a quote character of any
kind, or a word character, the last name token is a data variable.

Naturally, there are edge cases. Currently this does not allow for
something like `data.foo` or `data[0]`, but presumably can be extended
to do so.
This allows not only variable-like tokens as "direct data", but anything
not involving spaces or quotes.

Unfortunately disallowing quotes is necessary given strings can contain
anything, and data passed as object literal often contains strings. For
example, `{foo: "bar baz"}` could end up with the regular expression
matching the `baz"}` part, which is, of course, problematic.
@oscarotero oscarotero merged commit 48f42db into main Dec 12, 2025
1 check passed
@oscarotero oscarotero deleted the direct-data-for-include-and-layout branch December 12, 2025 16:30
@oscarotero
Copy link
Member

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to pass a variable directly to include or layout

3 participants