Widgets
Widgets let you reuse code across multiple pages without duplicating markup. They’re like small, reusable building blocks that you can drop into your content anywhere a shortcode is allowed.
Naming & Locations
Widgets are located inside of the widgets/ directory. The parser will first attempt to match the name of the shortcode to the name of a file in the widgets/ directory. For example, the shortcode [CUSTOM/] will first check for the following file
widgets/custom.tmpl
In the event that a file is not found, the parser will then replace underscores with slashes to allow for a nested folder structure. For example [NAV_SIDEBAR/] will look for the file:
widgets/nav/sidebar.tmpl
This allows for cleaner folder structure, as similair widgets can be grouped together.
Using Widgets
You call a widget using its shortcode. The shortcode name matches the widget file name (without the .tmpl extension):
[EXAMPLE xyz="abc"]
In this example, Genix will look for the widget file at widgets/example.tmpl. Within a widget, attributes passed through the shortcode can be referenced directly in the template. This makes it easy to customize the widget’s output without modifying its core structure. For instance, inside the widget template you can access the value of the attribute xyz using:
<p>This is my custom widget, [XYZ]</p>
This will result in the following text being compiled to the page:
<p>This is my custom widget, abc</p>
Content Reserved Word
In Genix, the shortcode [CONTENT] is a reserved word, and reference the content within an enclosing shortcode.
[CUSTOM]This is my custom text.[/CUSTOM]
In this example, the text "This is my custom text" can be referenced within the widget through the shortcode [CONTENT]
<p>[CUSTOM]</p>
Resulting in the following text being compiled:
<p>This is my custom text</p>