0

我正在尝试使用动态 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') ?>;}
4

2 回答 2

0

当您在 Joomla 环境之外的请求中时,您必须加载整个 joomla 框架。如何加载 Joomla 可以在这里找到JFactory failed to import。现在您可以通过数据库选择或加载更多类来选择模板参数以获取模板对象(不知道如何执行此操作,请不要使用我的开发笔记本电脑)。

于 2014-01-19T07:37:52.093 回答
0

您必须首先在包含模板参数的 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

`

于 2017-06-10T11:48:25.207 回答