-
Notifications
You must be signed in to change notification settings - Fork 9
Modules
Joomlatools Pages has built-in support for Joomla Modules. With Pages, modules no longer need to be instantiated and managed through the Joomla Module Manager.
Pages can create custom module positions, allowing you to dynamically inject content into any module position and can instantiate installed modules on the fly, passing in module parameters.
You can either create a "virtual" module and inject the content into the position you specify, or you can instantiate any installed module. The position to inject in can either be a position defined by your template or a custom position.
To create a module use the following syntax:
<ktml:module position="[position]">
[content]
</ktml:module>
where [position]
is the name of the position and [content]
is the content to be inserted.
To instantiate an installed Joomla module use the following syntax:
<ktml:module position="[position]" name="[module]">
where [position]
is the name of the position and [name]
is the module name to be created.
The <ktml:module>
syntax allows you to define additional module attributes as xml-style attributes.
The module title can be defined using the title
attribute. For example:
<ktml:module position="[position]" name="[module]" title="[My Module Tile]">
By default modules are prepended to the modules in the specified module position, to append a module instead add the prepend
attribute and set it to FALSE. For example:
<ktml:module position="[position]" name="[module]" prepend="false">
The module chrome can be defined through the style
attribute.
<ktml:module position="[position]" name="[module]" style="[style]">
Style can be a comma-separated list of different chromes, the module will be wrapped in FIFO order, meaning that the first defined style becomes the inner wrapper, and the last defined style the outer wrapper.
Note: If the modules position has its own style defined the module style will override this for this specific module.
Module parameters can be defined by passing a json string to the params
attribute, for example:
<ktml:module position="sidebar" name="menu" title="Side Menu" params="<?= json(['startlevel' => 1, 'endlevel' => 3, 'menutype' => 'mainmenu'], true); ?>">
To define a module position use the following syntax:
<ktml:modules position="[position]" condition="[condition]">
where [position]
is the name of the position and [condition]
is an optional condition. Only if the condition evaluates to TRUE the modules will be rendered.
A condition uses position names and supports following logic operators: + | - | * | / | == | != | <> | < | > | <= | >= | and | or | xor
.
For example
<html:modules position="sidebar" condition="sidebar >=2 and menubar != 0">
Will only render the sidebar modules if there are at least 2 modules injected in the position and the menu position is not empty.
If you want to wrap the modules inside a HTML element to apply additional styling you can for example do the following:
<khtml:modules position="sidebar" condition="sidebar >= 2">
<div class="modules">
<ktml:modules:content>
</div>
</ktml:modules>
The <ktml:modules:content>
element will be replaced with the modules and it allows you to wrap the modules with additional HTML, that will only be rendered if the sidebar contains at least two modules.
The <ktml:module>
syntax allows you to define additional position parameters as xml-style attributes.
The module chrome can be defined through the style attribute.
<ktml:modules position="[position]" style="[style]">
Style can be a comma-separated list of different chromes, the module will be wrapped in FIFO order, meaning that the first defined style becomes the inner wrapper, and the last defined style the outer wrapper.
Note: If an individual module in the position has its own style defined the modules style will not be applied.
Custom module position attributes are passed to the onRenderModule
and onAfterRenderModule
events and can be used by plugins. For more information please refer to the plugin documentation of the specific module plugin for more information on what parameters they support.
Got a question or need help? We have a forum on Github Discussions where you can get in touch with us.