- Get link
- X
- Other Apps
b:with
The b:with tag, or the variable tag, is a tag for calculating a variable value before it needs to be used, whether it is being set up to be available for nested b:include tag calls, or is simply a short-name for an ugly expression we don't want to use inline.
When the Blog gadget loads, any posts which are not labelled hide-me will still show, but all the posts which are labelled hide-me will not be rendered.
The next example re-uses a calculated title as the alt-text for an image as well as the content for an h1 tag.
Attributes
var - Name of the variable.
value - Expression for the value the variable will take.
Example usage
The following example overrides the Blog gadget's main includable to filter the lists of posts to exclude any posts labelled hide-me, by setting the data:posts variable's array to a filtered version of itself.
<widget id='Blog1' type='Blog'>
<b:includable id='main'>
<b:with var='posts'
value='data:posts filter
(p => p.labels none
(l => l.name == "hide-me"))'>
<b:include name='super.main' />
</b:with>
</b:includable>
</b:widget>
The next example re-uses a calculated title as the alt-text for an image as well as the content for an h1 tag.
<b:with var='title'
value='data:post.title ?: data:view.title ?: "Default title"'>
<a href='/foo'>
<img src='/bar' expr:alt='data:title.escaped' />
<h1><data:title></h1>
</a>
<b:include name='super.main' />
</b:with>