简体   繁体   English

Joomla 3:如何覆盖K2管理模板?

[英]Joomla 3: how to override K2 admin templates?

In Joomla 3 I have a need to specify different admin templates for K2 articles based on category to be able to specify different extra fields and make it easier for content contributors to add items. 在Joomla 3中,我需要根据类别为K2文章指定不同的管理模板,以便能够指定不同的额外字段,并使内容贡献者更轻松地添加项目。

I thought I'd found the perfect solution, but it was written several years ago for older versions of Joomla. 我以为我找到了理想的解决方案,但它是几年前为较早版本的Joomla编写的。 I did contact the author and he admitted writing it several years ago, has since quit using Joomla and was not able to advise me. 我确实联系了作者,几年前他承认写了这篇文章,此后就不再使用Joomla,也无法为我提供建议。

It is very similar to overriding front-end k2 templates. 它与覆盖前端k2模板非常相似。 Here is the article describing it: 这是描述它的文章:

http://getk2.org/documentation/tips-a-tricks/221-custom-admin-templates-and-calling-specific-extra-field-data http://getk2.org/documentation/tips-a-tricks/221-custom-admin-templates-and-calling-specific-extra-field-data

However when I do this and modify a category's admin template, there is no change from the default. 但是,当我这样做并修改类别的管理模板时,与默认设置没有任何变化。 My thought is that something in this code which modifies the file administrator/components/com_k2/views/item/view.html.php is not compatible with Joomla v.3: 我的想法是,这段代码中的某些修改文件administrator / components / com_k2 / views / item / view.html.php的内容与Joomla v.3不兼容:

//Look for specific admin template file  
jimport('joomla.filesystem.folder'); 
$componentPath = JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'templates'; 
$componentFolders = JFolder::folders($componentPath); 
$db =& JFactory::getDBO(); 
$query = "SELECT template FROM #__templates_menu WHERE client_id = 0 AND menuid = 0"; 
$db->setQuery($query); 
$defaultemplate = $db->loadResult(); 

if (JFolder::exists(JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid)) 
{  
$this->_addPath('template', 
JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid);  
}

Already, I know there is no table in my db with the name "templates_menu". 我已经知道数据库中没有名称为“ templates_menu”的表。 That threw an error immediately. 这立即引发了错误。 I believe it should template_styles", and most likely the columns should be client_id and id. Making those changes eliminated the error at least. 我认为应该使用template_styles”,并且最有可能的列应该是client_id和id。进行这些更改至少可以消除该错误。

Further, I believe the path is incorrect in the "if" statement. 此外,我认为“ if”语句中的路径不正确。 The second "templates" directory is not needed. 不需要第二个“模板”目录。

However, even after making these changes, I do not seem to be pulling in my new template on the admin side. 但是,即使进行了这些更改,我似乎也没有在管理方面引入新模板。

I am hoping a Joomla/PHP expert (which I am not) can weigh in here. 我希望有一个Joomla / PHP专家(我不是)可以在这里发表演讲。 I could be entirely wrong in my assumptions about the pathing and table name. 我对路径和表名的假设可能完全错误。

Edit: In researching this further, I decided to go ahead and CREATE the table that was indicated in the original poster's code. 编辑:在进一步研究中,我决定继续创建原始海报代码中指示的表格。 I now have a table in my database called e758z_templates_menu. 我的数据库中现在有一个名为e758z_templates_menu的表。

However, I still get nothing when trying to make Joomla use a custom admin template connected to a category ID. 但是,当尝试使Joomla使用连接到类别ID的自定义管理模板时,我仍然一无所获。 It continues to use the default one. 它继续使用默认值。

Can you not just create different extra filed groups and then assign the right ones to the right category? 您不仅可以创建其他多余的组,然后将正确的组分配给正确的类别吗?

If you modify the k2 core files then any changes will be wiped on an update, which, with the new 1-click updates would be quite likely. 如果您修改k2核心文件,则任何更改都会在更新时被擦除,而使用新的一键式更新很可能会进行更新。

You should be able to override the standard admin view with a standard template override, ie copy 您应该能够使用标准模板替代(即复制)替代标准管理视图

/administrator/components/com_k2/views/category/default.php /administrator/components/com_k2/views/category/default.php

to

/administrator/templates/YOUR_ADMIN_TEMPLATE/html/com_k2/category/default.php /administrator/templates/YOUR_ADMIN_TEMPLATE/html/com_k2/category/default.php

If you want them to be different for different categories then why don't you create a frontend login and then use different templates for different categories and override them in the standard way. 如果您希望它们在不同类别中有所不同,那为什么不创建前端登录名,然后对不同类别使用不同的模板,并以标准方式覆盖它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM