Provide rich parameter definitions
There are a number of cases where you may want to define a value for a parameter to be more complex than just the basic forms allowed by dust; viz p="abc", p=xyz, p="{xyz}". A very common case is to want the value from a helper function like {@size} that you can pass to a partial or test. @provide lets you capture that value and reference it like a parameter.
The general form of @provide is
{@provide [optional params]}
main block of dust
{:block1}
evaluation of this block defines a param named "block1"
{:block2}
evaluation of this block defines a param named "block2"
... as many blocks as you need params
{/provide}
Rules:
Examples:
Find the size of an array and pass the value to a partial
{@provide}
{>partial size=len /}
{:len}
{@size key=array /}
{/provide}
Create an ad hoc list of month numbers for a dropdown without the controller supplying them
{@provide selected=chosen}
<select name="months">
{#months}
<option value="{.}"{@if cond="'{selected}' == '{.}'"} selected="selected"{/if}>{.}</option>
{/months}
</select>
{:months}
[1,2,3,4,5,6,7,8,9,10,11,12]
{/provide}
Create an ad hoc structure to pass to a partial that expects a particular structure
{@provide}
{>displayAddress data=struct}
{:struct}
{"street":"{homeStreet}", "city":"{homeCity}", "state": "{homeState}" }
{/provide}