【发布时间】:2014-11-14 07:20:29
【问题描述】:
我有一个有两种样式的 joomla 模板。模板名称为default,样式为cats和arts。有没有办法返回当前使用的样式的名称。
下面的代码只返回模板的名称
$template = $app->getTemplate();
如果我做一个echo $template; 我得到默认值。但我想得到的是,我使用的是 cats 风格还是 arts
谢谢
【问题讨论】:
我有一个有两种样式的 joomla 模板。模板名称为default,样式为cats和arts。有没有办法返回当前使用的样式的名称。
下面的代码只返回模板的名称
$template = $app->getTemplate();
如果我做一个echo $template; 我得到默认值。但我想得到的是,我使用的是 cats 风格还是 arts
谢谢
【问题讨论】:
模板对象不包含模板样式变体的名称(因为它只是真正用作人类管理员的助记符)。
判断正在使用哪种“样式”的唯一方法是查看模板的id 值……该值将对应于您在“模板管理器”的 ID 列中看到的值 -样式”视图。
// Get the Joomla Application
$app = JFactory::getApplication();
// Get the template
$template = $app->getTemplate(true);
// Echo the ID
echo $template->id;
如果您真的需要“名称”,我认为您可能犯了设计错误,您可以尝试为$template->id 加载style 模型并以这种方式检索它。例如类似这样的内容(警告直接输入到 SO,未测试!)
// Initialise some vars
$name = 'Style';
$prefix = 'TemplatesModel';
$config = array();
// Get the model
$templateStyleModel = JModelLegacy::getInstance($name, $prefix, $config);
// Load the specific style instance.
$templateStyleModel->load($template->id);
// Echo out the style name
echo $templateStyleModel->title;
【讨论】:
$params = $app->getTemplate(true)->params;
使用 $params->get() 获取特定样式的参数。
【讨论】: