在joomla 3模板中使用css变量和php

在joomla 3模板中使用css变量和php,php,css,templates,joomla3.0,Php,Css,Templates,Joomla3.0,我的想法是使用joomla中的模板参数来设置背景、文本或按钮的颜色。 我想定义一个css类,而不是每次都使用style=“background color:;”,因为我不想编写无数的模板覆盖 我相信这是一个非常有用的特性 my templateDetails.xml中的参数如下所示 <field name="buttoncolor" type="color" default="#309000"

我的想法是使用joomla中的模板参数来设置背景、文本或按钮的颜色。 我想定义一个css类,而不是每次都使用style=“background color:
;”,因为我不想编写无数的模板覆盖

我相信这是一个非常有用的特性

my templateDetails.xml中的参数如下所示

<field name="buttoncolor" type="color" default="#309000"
                    label="TPL_BUTTON_COLOR_LABEL"
                    description="TPL_BUTTON_COLOR_DESC" />

如何在css中使用php变量的想法我在

要在css中使用php变量,我在index.php中链接了这个文件

<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/style.php" type="text/css"  />

请尝试删除
$this
。您的代码必须是:

  $app = JFactory::getApplication();
  $template = $app->getTemplate(true);
  $params = $template->params;
  $buttoncolor = $params->get("buttoncolor");
Joomla有一种特殊的设置方式。你必须像这样做:

  $document = JFactory::getDocument();
  $style = ".buttoncolor {background-color: ".$buttoncolor."}"; 
  $document->addStyleDeclaration($style);

祝你好运

您好,非常感谢您的解决方案。如果我对每件事都理解正确,那么就没有理由包含style.php。它工作得很好,我从未想过解决方案会如此简单。再次感谢。确保这种方式不需要额外的文件包含。不客气!
  $app = JFactory::getApplication();
  $template = $app->getTemplate(true);
  $params = $template->params;
  $buttoncolor = $params->get("buttoncolor");
  $document = JFactory::getDocument();
  $style = ".buttoncolor {background-color: ".$buttoncolor."}"; 
  $document->addStyleDeclaration($style);