Build or Override a Widget
Last updated
Last updated
© Astroid Framework 2023.
Widget is part of Astroid's Element system and is used to create display elements in Layout Builder or Article Builder. The structure of a widget includes an xml file and a php file.
The XML file is used to declare fields like a Joomla Extension
The PHP file is used to query, execute and display results
The system will scan widgets from folders with the following priority order:
media/templates/site/{YOUR_TEMPLATE_NAME}/astroid/elements
plugins/astroid/{YOUR_PLUGIN_NAME}/elements
libraries/astroid/framework/elements
To create or override a widget you need to create a folder {WIDGET_NAME}
in the JROOT/media/templates/site/{YOUR_TEMPLATE_NAME}/astroid/elements/
folder with an xml file and a php file
{WIDGET_NAME}.xml
{WIDGET_NAME}.php
You are a Joomla extension developer and want to create widgets for Astroid so that you can easily include them in your templates or 3rd party templates without having to use template override. So using Astroid element plugin is the easiest way.
You can download Example plugin below >> extract ZIP file and try with it. This is a Joomla plugin, so you can install it via administrator >> System >> Install Extensions >> Upload package file
When you upload plugin successfully. Go to Template Options >> Layout >> Add Element >> You can see it
Go to ROOT/plugins/astroid/plg_elements_example/elements
You can see the structure
I am taking an example of a simple xml structure of Icons Widget below
title (required): Declare the name of the Widget you want to create.
description: Declare the description of the Widget
icon (required): Font Awesome class you can find them at https://fontawesome.com/
category (required): Declare the category of the Widget
element_type (required): There are 3 types of widget_type: system, widget, article
. You can only choose 1 of the 3.
In PHP file you simply display what you want with widget. You can use $param->get()
variable to call out the widget params defined in XML file. Let's see the example below.
To use the your widget, go to Administrator > Template Manager > select your Template > Template Options > Layout Builder
Create a block and Add Element. In the Element selection section, you will see your Widget as shown in the example image below. I created a Test Widget.