【发布时间】:2014-09-07 20:28:19
【问题描述】:
我的想法是在 joomla 中使用模板参数来设置背景、文本或按钮的颜色。
我想定义一个 CSS 类,而不是每次都使用 style="background-color:<?php echo $buttoncolor ?>;"因为我不想写无数的模板覆盖。
我相信这可能是非常有用的功能。
我的 templateDetails.xml 中的参数看起来像
<field name="buttoncolor" type="color" default="#309000"
label="TPL_BUTTON_COLOR_LABEL"
description="TPL_BUTTON_COLOR_DESC" />
我在 CSS-Tricks找到的如何在css中使用php变量的想法
要在我的 index.php 中链接到这个文件的 css 中使用 php 变量
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/style.php" type="text/css" />
我的 style.php 看起来像:
<?php
header("Content-type: text/css; charset: UTF-8");
$buttoncolor = $this->params->get("buttoncolor");
?>
.buttoncolor {background-color: <?php echo $this->params->get('buttoncolor'); ?>;}
通常我在 index.php 中将变量设置为模板参数,例如
<?php
//parameter
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$params = $app->getParams();
$buttoncolor = $this->params->get('buttoncolor');
?>
不幸的是,我收到以下错误: 致命错误:在 style.php 中不在对象上下文中时使用 $this
非常感谢任何想法、解决方法和帮助!
【问题讨论】:
标签: php css templates joomla3.0