XMLForm with Custom Template - Pie Chart

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
        • /classes/
          • piecharthelper.php

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

  • Fantastic
  • Mind Blowing
  • Unbelievable

Why is this software free?

I’m ditching the freemium game and giving this software to the Joomla crowd for free. It’s a nod to “Jumla”—Swahili for “all together”—because fragmentation sucks, and I’d rather focus on innovation and paid gigs. Use it, build with it, and if you need custom work, I’m super into that.

What's The Catch?

There isn’t one! I’m all about building tools that empower the Joomla community and spark creativity. This software’s free because I’d rather see it in your hands - fueling awesome projects. If you really feel like paying something, I’d appreciate a review in the Joomla Extension Directory—your feedback means a lot!