![](/img/trans.png)
[英]How to $_GET [' '] value from $document->addStylesheet() in mod_modulenamet/mpl/default.php to css.php file of joomla module
[英]Joomla dynamic stylesheet using template parameters in a css.php file
我正在尝试使用动态css.php文件创建模板。 我花了一整夜的时间来寻找一种解决方案,以在用作css文件的php文件中调用joomla对象类。 我知道我以前看过这件事,但是我从来没有注意过它是如何完成的。 到目前为止,这就是我所拥有的。
注意-我不想使用addstyledecloration,因为它在处理多个参数时过于繁琐*
index.php:
<?php
defined('_JEXEC') or die;
require($this->baseurl.'templates/'.$this->template.'/includes/config.php');
?>
<!DOCTYPE html>
<html lang="en" xmlns:fb="http://ogp.me/ns/fb#">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<jdoc:include type="head" />
</head>
config.php:
<?php
defined('_JEXEC') or die;
//joomla configuration
JLoader::import('joomla.filesystem.file');
JHtml::_('jquery.framework', false);
JHtml::_('bootstrap.framework');
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$doc = JFactory::getDocument();
$template_path = $this->baseurl.'/'.'templates'.'/'.$this->template;
$jui_path = $this->baseurl.'/media/jui';
$doc->addStyleSheet($jui_path.'/css/bootstrap.min.css');
$doc->addStyleSheet($jui_path.'/css/bootstrap-responsive.min.css');
$doc->addScript($jui_path.'/js/bootstrap.min.js');
$doc->addStyleSheet($template_path.'/css/template.css');
$doc->addStyleSheet($template_path.'/includes/template-css.php');
$doc->addScript($template_path.'/js/template.js');
?>
template-css.php:
<?php
header("Content-type: text/css");
?>
body {background-color: #000;}
body {background-color: <?php $this->params->get('body') ?>;}
在Joomla环境之外的请求中,您必须加载整个joomla框架。 如何加载Joomla可以在此处找到JFactory导入失败 。 现在,您可以通过数据库选择模板参数,或者选择更多类以获取模板对象(不确定如何执行此操作,不要随身携带我的开发笔记本电脑)。
您必须首先在templatedetails.xml中添加一个颜色选择器,其中包含模板参数
<field name="themecolor" type="color" description="Color picker" label="Template Color"/>
然后,您必须在config.php文件中声明该变量
$themecolor = $this->params->get('themecolor');
$_SESSION['themecolor'] = $themecolor;
现在您将可以在css.php文件中使用此变量
body {background-color: <?php echo $_SESSION['themecolor']; ?>}
您可以在这里阅读有关模板参数的更多信息https://docs.joomla.org/Understanding_Joomla!_templates#Parameters
`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.