Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Block Module

Latest Version Software License Quality Sblock SensioLabs Insight CodeClimate Total Downloads Slack

Branch Travis-ci
master Build Status
2.0 Build Status



You can install the Block module, with the following command which allows the module to be edited for your project.

php artisan asgard:download:module asgardcms/block --migrations


You can install the Block module with composer:

$ composer require asgardcms/block

Then run the following command to install the database tables:

$ php artisan module:migrate Block


In the backend GUI, go to Users > Roles > Admin. Then the permissions tab, and give the Admin role the permissions for the block module.


This is a very simple module to create re-usable blocks of content. The blocks of content are created in the administration. You give it a name and a content.

After this, you'll be able to get the content of a block with the following code:

{!! Block::get('block-name') !!}

Each block also receives a shortcode that can be used instead of the code mentioned above. Shortcode looks like this [[BLOCK(block-name)]].
This is very useful if you for example want to allow users to reuse and enter blocks into content of the WYSIWYG editor (page or blog article body)

If you want to use shortcodes in your app, you need to register RenderBlock middleware responsible for parsing the response and replacing the shortcodes with the actual block content. It can be done globally by editing app/Http/Kernel.php file and adding \Modules\Block\Http\Middleware\RenderBlock::class into the $middlewareGroups web group (this way, block shortcodes will be automatically replaced in all web routes on frontend):

    // app/Http/Kernel.php
    protected $middlewareGroups = [
        'web' => [

There are some drawbacks to this approach, specifically that each response will be parsed and searched for the shortcodes before returning back to the user, which may slightly slow down your application. If you know that you do not need to use shortcodes in the whole app, middleware can be applied selectively only to some routes or route groups in your application:

    // Modules/YourModule/Http/frontendRoutes.php
    // middleware will be applied to this specific route
    $router->get('your-url', 'YourController@method')
    // middleware will be applied to whole group
    $router->group(['middleware' => \Modules\Block\Http\Middleware\RenderBlock::class], function(Router $router) {
        $router->get('your-url', 'YourController@method');

Keep in mind that by allowing users to put blocks/shortcodes anywhere, you are creating a potential security issue, so use this functionality carefully.


Hooks are special events, where it allows you to change the data stored before it's stored in the database.


Triggered before a block is created.


Triggered before a block is updated.


Triggered when a block body gets displayed.



All AsgardCMS modules respect Semantic Versioning.