简体   繁体   中英

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.

I thought I'd found the perfect solution, but it was written several years ago for older versions of 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.

It is very similar to overriding front-end k2 templates. Here is the article describing it:

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:

//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". 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.

Further, I believe the path is incorrect in the "if" statement. 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. 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.

However, I still get nothing when trying to make Joomla use a custom admin template connected to a category 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.

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

to

/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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