Mantra how-to guide

How to declare an anonymous block

Blocks are pieces of HTML content you can add whenever you need: views, html roots or other blocks

07-Mar-2022
A  A  A 

Mantra blocks are supposed to be small pieces of HTML content so that you can insert them in any view, HTML root documents or other blocks.

As described in blocks documentation, a component has the ability to implement a function handler to render a specific block every time it is needed. To do this, the block and its function handler should be "registered" as any other kind of Mantra hooks.

However, in the case of blocks, Mantra considers anonymous blocks as well: they are defined in their own file inside "/ui/blocks" folder of the document and they doesn't need to be explicity redirected.

Suppose this block file located at "/ui/blocks/sitename-block.html"

<div class="row">
   <div class="col">This is the name of my site</div>
</div>

Despite not having any render function handler or hook registering, Mantra looks up it then the application start and self registers the block with the name of its file, in this case: "sitename-block".

By doing so, you can insert this block in any block view, HTML document or other block with standard Mustache brackets:

{{{sitename-block}}}

Anonymous blocks are fast ways to define small pieces of static HTML code that you can reuse along your project.