【问题标题】:How to get Joomla template style name?如何获取 Joomla 模板样式名称?
【发布时间】:2014-11-14 07:20:29
【问题描述】:

我有一个有两种样式的 joomla 模板。模板名称为default,样式为catsarts。有没有办法返回当前使用的样式的名称。

下面的代码只返回模板的名称 $template = $app->getTemplate(); 如果我做一个echo $template; 我得到默认值。但我想得到的是,我使用的是 cats 风格还是 arts

风格

谢谢

【问题讨论】:

    标签: templates joomla


    【解决方案1】:

    模板对象不包含模板样式变体的名称(因为它只是真正用作人类管理员的助记符)。

    判断正在使用哪种“样式”的唯一方法是查看模板的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;
    

    【讨论】:

      【解决方案2】:

      $params = $app->getTemplate(true)->params;

      使用 $params->get() 获取特定样式的参数。

      【讨论】:

      • $params->get() 需要一个参数。但我找不到当前样式的任何论据
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-02
      • 2015-01-11
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      相关资源
      最近更新 更多