Outputting
Once you've stored some flexible content in the database you are probably going to want to display it on the frontend.
As long as you've added the Yadda\Enso\Crud\Traits\HasFlexibleFields trait to your model you can use the @flexibleField blade directive to output your data. E.g.:
@flexibleField($my_model, 'my_field', 'some-class', 'some-template', 'some-id')
In this example:
$my_model- an instance of a model with theHasFlexibleFieldstrait appliedmy-field- the name of the flexible content columnsome-class(optional) - a class which will be used as the base for a BEM class structure instead of the default classflexible-contentsome-tempalte(optional) - a template which will be used instead of the default templateenso-crud::flex-partials.flexible-content. Passing null will use the default.some-id(optional) - an id which is used to generate row id's instead of using the field_name.
Views
When the @flexibleField directive is used it will run through each row in the data.
The default row view will output each block (i.e. field) within the row and output a corresponding view. There are default block-level templates for each field type. You can override these views with your own, either at the row or block level.
Row
Create a view named $row->getRowType() in views\vendor\enso-crud\flex-partials\rows\.
In Row views you will have access to a variable called $row which is an instance of Yadda\Enso\Crud\Handlers\FlexibleRow.
This class includes the helper methods block($name) and setting($name) which allow you to get a block or settings block by name.
Block
Blocks in this context represent the sub-fields with a Row. You can think of them as fields but having a separate word prevents confusion.
To override a block view specific to a row type. A matching block blade template in views\vendor\enso-crud\flex-partials\blocks\{$row->getType()}\{$block->getType()}.blade.php. E.g. views\vendor\enso-crud\flex-partials\blocks\intro\text.blade.php
If the above does not exist, a default view will be loaded from views\vendor\enso-crud\blocks\.
In Block views you will have access to a variable called block which is an instance of Yadda\Enso\Crud\Handlers\FlexibleBlock.