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

58 lines
1.6 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](../../flow/) you need to define flow block models.
If you are not familiar with Flow yet, you should read the [Introduction
Documentation](../../flow/) to Flow first.
## 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 `[models]` as section, the section is called `[block]`.
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
which an be used to customize the label of the button that adds blocks to
a flow.
## Templates
Now that we have a model for our flow block, we need to create a template
for it. When a flow block is added to a Flow, it will automatically
render it by default through the template `blocks/NAME.html` (so in our
case `blocks/text.html`). Here is a suitable template for this:
```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.