Template Renderer
Renders structured data to a predefined template.
---
block:
_bookshop_name: layouts/template-renderer
variable_name: collections.demo_collection
template_name: demo
filter:
field: null
equals: null
limit: null
offset: null
---
{% bookshop "{{block._bookshop_name}}" bind: block %}
Properties
variable_namestring
The string representation of the object you want to use for templating.
data_objectobject
Used instead of variable_name
, this option lets you pass a data object directly.
template_namestring
The name of the template in _templates
.
filtersobject
Filters for narrowing down the passed data.
fieldstring
If set, it will filter the data set on this field
equalsstring
The value to match on the filtered field.
limitnumber
Limits the number of items in the data.
offsetnumber
Offsets the items in the data.
Examples
Filtering
---
block:
_bookshop_name: layouts/template-renderer
variable_name: collections.demo_collection
template_name: demo
filter:
field: data.region
equals: Canterbury
limit: null
offset: null
---
<h3>Items with Canterbury region only</h3>
{% bookshop "{{block._bookshop_name}}" bind: block %}
---
block:
_bookshop_name: layouts/template-renderer
variable_name: collections.demo_collection
template_name: demo
filter:
field: null
equals: null
limit: 3
offset: null
---
<h3>3 item limit</h3>
{% bookshop "{{block._bookshop_name}}" bind: block %}
---
block:
_bookshop_name: layouts/template-renderer
variable_name: collections.demo_collection
template_name: demo
filter:
field: null
equals: null
limit: 1
offset: 3
---
<h3>1 item limit, offset by 3</h3>
{% bookshop "{{block._bookshop_name}}" bind: block %}
Data Passing
---
block:
_bookshop_name: layouts/template-renderer
variable_name: collections.demo_collection
template_name: demo
filter:
field: null
equals: null
limit: null
offset: null
---
{% bookshop "{{block._bookshop_name}}" bind: block %}
---
block: null
---
<h3>Passes an object to template-renderer that's pre-filtered to only items that include a "Hiking" activity.</h3>
{% assign data = collections.demo_collection | where_exp: "item", "item.data.activities contains 'Hiking'" %}
{% bookshop "layouts/template-renderer" data_object:data template_name: "demo" %}
---
block:
filter:
field: null
equals: null
limit: null
offset: null
_bookshop_name: layouts/template-renderer
variable_name: pagination.items
template_name: demo
pagination_example:
note: >-
This property should just be named `pagination`, but we've used
`pagination_example` here to show how pagination works without interfering
with the pagination object.
data: collections.demo_collection
size: 3
generatePageOnEmptyData: true
---
<h3>It can handle objects generated by 11ty like pagination.</h3>
{% bookshop "{{block._bookshop_name}}" bind: block %}
---
block:
_bookshop_name: layouts/template-renderer
variable_name: macro_component
template_name: macro
filter:
field: null
equals: null
limit: null
offset: null
macro_component:
heading: This is a Macro Component
icon: hand-thumb-up
paragraph: >-
It's hides all of the complexity of a component nest and allows you to
expose a simple interface to the editor.
---
{% bookshop "{{block._bookshop_name}}" bind: block %}