Twig/Blade
The following is a basic example of how to render a Bloqs field with nested bloqs using Twig. If you're using Blade, the concepts are identical, just slightly different syntax for Blade.
Note the include statements are passing an array of possible template names to include in the brackets. If the first template file is not found, it will skip it and attempt to render the next one. For example, if you have a bloq named "summary" and you want that bloq to render entirely different HTML, just create a template named _bloq_summary.html
All other bloqs will render in the _bloq.html
template. These template names are completely arbitrary and you can choose any names you want. In this example I have a coilpack.group
folder with the _bloq.html.twig
and _atom.html.twig
templates inside.
If in this scenario there was an atom with the short name of content_with_image
, and a template file named _atom_content_with_image.html.twig
existed, it would be loaded instead of the _atom.html.twig
template.
Twig is extremly flexible and there are probably a number of ways to approach building out a Bloqs field. This is a basic example of how to use an include to render a deeply nested Bloqs field.
Once you have a bloq variable you can access it's atoms and atom values directly via the dot notation:
Relationships
Accessing relationship field data in Twig or Blade is the same as accessing any other array.
Last updated
Was this helpful?