Templates & Modules views - lucbu/AngkorCMS GitHub Wiki

Display modules / Customizing the display

The method

In the template, you'll have to display each blocks like this:

{!! 
    AngkorBlade::display(
        $blocks['body'], (1)
        $parameters, (2)
        $attributes, (3)
        $attributesToView (4)
    ) 
!!}
  1. Name of the block to display
  2. parameters sent by the CMS
  3. Optional, attributes used to create html element(s) around each modules
  4. Optional, attributes to pass to modules

Creating the variable $attributes

This variable will be usefull only if the variable 'showDiv' in the config files of the module is set to false.

If you declare juste one HTML element being around the module, you'll have to set an array it the principal array (Example: [["type"=>"section"]])

Each key you add can be declare as an array, the value will loop. Several key are available :

  • id (boolean) : if you want to display the module title as id in the html element (false by default)
  • type (string) : if you want to modify the type of the html element ("div" by default)
  • stop (boolean): if you want to stop the loop at the end of the array of the key (false by default)

You can set for example a single class for each module with only one div around the module:

  • [["class" => "className"]]
            <div class="className">
                <span id='unique_id'>
                    //module 1 result
                </span>
            </div>
            <div class="className">
                <span id='unique_id'>
                    //module 2 result
                </span>
            </div>

You can also set two class that will loop indefinitely in section's element:

  • [["type" => "section", "class"=>["class1", "class2"]]]
            <section class="class1" id="module1->title">
                <span id='unique_id'>
                    //module 1 result
                </span>
            </section>
            <section class="class2" id="module2->title">
                <span id='unique_id'>
                    //module 2 result
                </span>
            </section>
            <section class="class1" id="module3->title">
                <span id='unique_id'>
                    //module 3 result
                </span>
            </section>

Two html elements around module with stop option:

  • [["type" => "section", "class"=>["class1", "class2", "stop" => true]], ["type" => "row", "class"=>"classRow"]]
                <section class="class1">
                    <row class="classRow">
                        <span id='unique_id'>
                            //module 1 result
                        </span>
                    </row>
                </section>
                <section class="class2">
                    <row class="classRow">
                        <span id='unique_id'>
                            //module 2 result
                        </span>
                    </row>
                </section>
                <section class="class2"> // Stil Class 2 (no Loop)
                    <row class="classRow">
                        <span id='unique_id'>
                            //module 3 result
                        </span>
                    </row>
                </section>

Accessible parameters in modules' views

In views, you have access to several things :

  • $unique_id: An unique id that can be used to define html tag(s).

  • $module: The module with his 'name':string, 'title':string, 'nature':string, 'unique':boolean, 'lang':AngkorCMSLang

  • $'module-name': The module define by the package that declare it. (for example slideshows)

  • $parameters: Array containing "url_base" that is the url created with the slug of the AngkorCMSPageTrans that the visitor is currently on

  • $attributes: Attributes used to create div around each modules (3) (The modules are already created but you can still have access to it)

  • $attr: attributes to pass to modules (4), Attributes that you can use in your modules to allow user to customize plugins (for example letting them choose the CSS class of some HTML elements)

Display views like a full module

In the module you can use the function

AngkorBlade::createViewAsModule($view, $attributes, $data)

  • $view : the path to the view to display
  • $attributes : just pass the $attributes the view is getting
  • $data : data the value need to be displayed

It'll make the view look like a module (can be usefull for example to list the news)

⚠️ **GitHub.com Fallback** ⚠️