
Turns out explicit context setting works in a lot more places than the official dustjs pages indicate. Also some things don't make much sense (like setting it on a block works but not on an inline partial).
160 lines
3.4 KiB
Plaintext
160 lines
3.4 KiB
Plaintext
{! First we do it without explicit context setting which results in being able to read some_global but not pet !}
|
|
Section Regular{~n}
|
|
==============={~n}
|
|
{#loop}
|
|
{#person}
|
|
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|
|
{! Then we do it with explicit context setting which should result in being able ot read pet but not some_global !}
|
|
Section Explicit{~n}
|
|
================{~n}
|
|
{#loop}
|
|
{#person:explicit}
|
|
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|
|
{! What happens if we try to use an explicit context with an exists block instead of a section !}
|
|
Exists Regular{~n}
|
|
=============={~n}
|
|
{#loop}
|
|
{?person}
|
|
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|
|
Exists Explicit{~n}
|
|
==============={~n}
|
|
{#loop}
|
|
{?person:explicit}
|
|
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|
|
{! Can you explicitly set the context for a partial? !}
|
|
Partial Regular{~n}
|
|
==============={~n}
|
|
{#loop}
|
|
{>other/}
|
|
{/loop}
|
|
|
|
Partial Explicit{~n}
|
|
================{~n}
|
|
{#loop}
|
|
{>other:explicit/}
|
|
{/loop}
|
|
|
|
Quoted Partial Explicit{~n}
|
|
======================={~n}
|
|
{#loop}
|
|
{>"other":explicit/}
|
|
{/loop}
|
|
|
|
Partial Regular with parameters{~n}
|
|
==============================={~n}
|
|
{#loop}
|
|
{>other pet="rabbit"/}
|
|
{/loop}
|
|
|
|
Partial Explicit with parameters{~n}
|
|
================================{~n}
|
|
{#loop}
|
|
{>other:explicit pet="rabbit"/}
|
|
{/loop}
|
|
|
|
{! Can you explicitly set the context for a helper? !}
|
|
Helper Regular{~n}
|
|
=============={~n}
|
|
{#loop}
|
|
{@eq key="foo" value="foo"}
|
|
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
|
|
{/eq}
|
|
{/loop}
|
|
|
|
Helper Explicit{~n}
|
|
==============={~n}
|
|
{#loop}
|
|
{@eq:explicit key="foo" value="foo"}
|
|
{$idx}: {person.name} has a pet {pet} but not a {some_global}{~n}
|
|
{/eq}
|
|
{/loop}
|
|
|
|
{! Can you explicitly set the context for inline partials or blocks? !}
|
|
Block Regular{~n}
|
|
============={~n}
|
|
{#loop}
|
|
{>default/}
|
|
{/loop}
|
|
|
|
Inline Partial Regular{~n}
|
|
======================{~n}
|
|
{#loop}
|
|
{>override/}
|
|
{/loop}
|
|
|
|
Block Explicit{~n}
|
|
=============={~n}
|
|
{#loop}
|
|
{>default_explicit/}
|
|
{/loop}
|
|
|
|
Inline Partial Explicit{~n}
|
|
======================={~n}
|
|
{#loop}
|
|
{>override_explicit/}
|
|
{/loop}
|
|
|
|
Inline Partial and Block Explicit{~n}
|
|
================================={~n}
|
|
{#loop}
|
|
{>override_double_explicit/}
|
|
{/loop}
|
|
|
|
{! Can you explicitly set the context for references? !}
|
|
{! Commented out until I add support for rendering invalid dust verbatim
|
|
Reference Regular{~n}
|
|
================={~n}
|
|
{.}{~n}
|
|
|
|
Reference Explicit{~n}
|
|
=================={~n}
|
|
{.:some_global}{~n}
|
|
!}
|
|
|
|
{! Can you explicitly set the context with a path? !}
|
|
Path Regular{~n}
|
|
============{~n}
|
|
{#loop}
|
|
{#person}
|
|
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|
|
Path Explicit{~n}
|
|
============={~n}
|
|
{#loop}
|
|
{#person:deep_explicit.explicit}
|
|
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|
|
{! Can you explicitly set the context to a variable? !}
|
|
Variable Regular{~n}
|
|
================{~n}
|
|
{#loop}
|
|
{#person}
|
|
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|
|
Variable Explicit{~n}
|
|
================={~n}
|
|
{#loop}
|
|
{#person:$idx}
|
|
{$idx}: {name} has a pet {pet} but not a {some_global}{~n}
|
|
{/person}
|
|
{/loop}
|
|
|