Custom HTML in Joomla Template Manager

2019-08-15 05:50发布

问题:

While developing a Joomla Template, i got stuck on this qeustion.

Every Joomla Module has a manifest. In that manifest you can set your Paramaters for your template with Field and Fieldset types. Is it possible to add a custom image in these sections? I tried CDATA for this but it doesn't work.

回答1:

I've never tried this with a template, only a plugin and module, but I believe it's still the same concept.

Create a new folder in your template folder and name it "elements".

Then, in your template.xml file, find the <fieldset> that the parameter belongs to and add the following inside the tag:

addfieldpath="/modules/mod_social_slider/fields"

You now need to add a new parameter field like so:

<field name="image" type="custom" default="" label="" description="" />

Now, create a new PHP and place it inside your newly created "elements" folder and call it "custom.php". Then add the following code:

<?php

defined('_JEXEC') or die('Restricted access');

class JFormFieldCustom extends JFormField {

    protected $type = 'Custom';

    protected function getInput() {
        return '<img src="' . JUri::root() . 'templates/your_template/images/image.jpg" alt="" />';
    }

}
?>

Note that I haven't tested this so let me know if it works or not