php - Joomla 动态样式表在 css.php 文件中使用模板参数

标签 php css joomla joomla3.2

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

最佳答案

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

关于php - Joomla 动态样式表在 css.php 文件中使用模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21199731/

相关文章:

javascript - 从 JOOMLA 中的 javascript 捕获任何表单

php - 在 Laravel 的 artisan 队列 :listen 中捕获 ProcessTimedOutException

php - 使用 UNION 查询 MySQL,我在选择的列之一上遇到错误

javascript - @media 用于 Javascript 文本动画

html - 如何在 laravel 邮件模板中使用 bootstrap

php - PHP函数parse_ini_file()真的有那么危险吗?

php - MySQL Table does not exist 错误,但确实存在

php - 文件权限和 CHMOD : How to set 777 in PHP upon file creation?

css - JSF-h :panelGrid specific style for specific column

css - 对齐搜索模块 : Joomla responsive website