简体   繁体   中英

getting Joomla category params

I have a color param in Joomla 3.0 component category. 

and here is the div I want to give bg color.

I appreciate your answer.

category.xml


$app = JFactory::getApplication();


$template = $app->getTemplate(true);
  $params = $template->params;
  $eventcolor = $params->get("eventcolor");

I need to get my color param in my module and echo to my div background color. here is my code.

<div class="square" style="background-color:<?php echo $this->params->get('eventcolor'); ?> !important;"></div>

 <form> <fields name="params"> <fieldset name="basic" label="Color settings"> <field name = "eventcolor" type = "color" default = "frontpage" validate = "color" class="input-colorpicker" value="#000" size="10" label = "Kleur" required = "true" description = "Kies een event kleur" </field> </fieldset> </fields> </form> 

If you already get

$eventcolor = $params->get("eventcolor");

Just echo $eventcolor

In the main php file of a module, you have the variable $params available. But you try to use $this->params which is usually not available. To make your code work, please try this:

<div class="square" style="background-color:<?php echo $params->get('eventcolor'); ?> !important;"></div>

Not sure why you have that code part:

$template = $app->getTemplate(true);
$params = $template->params;
$eventcolor = $params->get("eventcolor");

It is not necessary if you use the main PHP file of a module.

Since I'm not sure you are in the same component context, you need to use a code similar to this one in order to get the params list from the right component helper:

$params = JComponentHelper::getParams( 'com_yourcomponent' );

Then, you can get and print the param in the way you were already doing:

<div class="square" style="background-color:<?php echo $params->get('eventcolor'); ?> !important;"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM