lektor-website/content/docs/models/flow/contents.lr

63 lines
1.8 KiB
Plaintext
Raw Normal View History

2015-12-19 14:52:17 +01:00
title: Flow Block Models
---
summary: Explains how to model flow blocks.
---
body:
To use [Flow :ref](../../content/flow/) you need to define flow block models.
2015-12-19 14:52:17 +01:00
If you are not familiar with Flow yet, you should read the [Introduction
Documentation](../../content/flow/) to Flow first.
2015-12-19 14:52:17 +01:00
## Defining Models
Flow block models work pretty much exactly the same as [Regular Models
:ref](../). The differences are mostly minor and of cosmetic nature. They
are stored in the `flowblocks/` folder and are ini files just like models.
Instead of using `[model]` as section, the section is called `[block]`.
2015-12-19 14:52:17 +01:00
Here a very basic flow block model `flowblocks/text.ini`:
```ini
[block]
name = Text Block
button_label = Text
[fields.text]
label = Text
type = markdown
[fields.class]
label = Class
type = select
choices = default, centered
choice_labels = Default, Centered
default = default
```
This should be self explanatory. One thing that is different about blocks
compared to regular models is that they support the `button_label` attribute
2018-05-14 05:07:59 +02:00
which can be used to customize the label of the button that adds blocks to
2015-12-19 14:52:17 +01:00
a flow.
## Templates
Now that we have a model for our flow block, we need to create a template
2016-07-13 09:12:29 +02:00
for it. Templates for blocks are stored in the `blocks` subdirectory of the
`templates` folder.
The name for the block template is automatically derived from the config file
that keeps the flow block definition (`templates/blocks/NAME.html`):
In our case the expected template is `templates/blocks/text.html`,
as our flow block is defined in a file called `text.ini`.
Here is a suitable template for this:
2015-12-19 14:52:17 +01:00
```html+jinja
<div class="text-block text-block-{{ this.class }}">
{{ this.text }}
</div>
```
If you need to access the page the flow is used by, you can use the `record`
template variable.