我正在尝试使用动态 css.php 文件创建模板。我花了一整夜的时间在谷歌上搜索一个解决方案,以在用作 css 文件的 php 文件中调用 joomla 对象类。我知道我以前见过这样做,我只是从未注意它是如何完成的。这就是我到目前为止所拥有的。
注意 - 我不想使用 addstyledecloration 因为它在处理多个参数时太麻烦 *
索引.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>
配置.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');
?>
模板-css.php:
<?php
header("Content-type: text/css");
?>
body {background-color: #000;}
body {background-color: <?php $this->params->get('body') ?>;}