This example builds upon XMLForm with Language Files and XMLForm Basic File System Setup, while adding a custom template output.
I ran across an article about CSS pie charts, and I thought this would be a great example to turn into an XMLForm template tutorial.
Download the package here: piechart.zip
Field / File System Structure
- JPATH_ROOT/
- /subforms/
- /piechart/
- piechart.xml
- piechart.php
- /language/
- /en-GB/
- piechart.ini
- /en-GB/
- /classes/
- piecharthelper.php
- /piechart/
- /subforms/
JPATH_ROOT/subforms/piechart/piechart.xml
As described in the previous simple examples, this file name sets the base name for the template and the language files. Files in the classes subdirectory can be named whatever you want, because they're not part of an XMLForm definition. This is a pretty standard Joomla compatible XML form definition. It contains a repeatable subform, allowing entry of multiple data elements for the chart.
JPATH_ROOT/subforms/piechart/piechart.php
This is mostly a shell, because the actual chart is created by the helper. This example identifies if you have enabled the multiple setting for the field, and handles the outputs differently based on that setting.
JPATH_ROOT/subforms/piechart/language/en-GB/piechart.ini
This is a pretty standard Joomla language INI file. As long as you aren't re-using existing language constants, you can use pretty much whatever you want here. Adopting a standard is probably a good idea. In this case, all of the constants are prefixed with XMLFORM_PIECHART_ - which should make it pretty safe.
JPATH_ROOT/subforms/piechart/classes/piecharthelper.php
This does the heavy lifting, pretty self-explanatory.
The Field Settings
This XMLForm is running/configured in this article! The settings I used were:
- Form Source: subforms/piechart/piechart.xml
- Load Language: Yes
- Load Template: Yes
- Groupby Fieldset: No
- Multiple: No
The Field Data
Just some opinions on Rush albums, you'll see.
The Result
Quality of Rush Albums
Legend