Saturday, 24 October 2009 19:08

K2: Custom Templates Featured

Written by
Rate this item
(3 votes)

To override layouts in K2, you follow nearly the same process that you would in the Native Joomla content component. There is one slight difference though. It would seem that K2 . 

Let's take the item view for example. Just before the JView::display method is called at the end of the K2ViewItem class the following is executed:

 //Set template paths
        $this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.'default');
        $this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates'.DS.'default');
        if ($params->get('theme')) {
            $this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.$params->get('theme'));
            $this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates'.DS.$params->get('theme'));
        }

The '$this' part of each of these lines is referring to the an object that extends the JView class. The _addPath method puts the given path on top of an array of paths to search. What that means is that when  JView::display is finially called the method will look for the define layout in the folders that have been defined in the JView::_path property, returning the first layout it finds starting at the top of the JView::_path array.

From the code above its aparent that if we have a special theme set for this content item, the JView class will look for the item.php in the :

JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates'.DS.$params->get('theme')

which kind of looks like this:

/myJoomlaRoot/templates/myCurrentDefaultTemplate/html/com_k2/templates/myK2ThemeParameter/

Read 11923 times Last modified on Saturday, 24 October 2009 19:40
Cameron

Cameron is a PHP Application Developer and consultant and spends much of his time furthering the business goals of his company Magnetic Merchandising Inc. which he started in 2005.

Cameron has provided technical deployment and consultation for many entities since starting MMI. Much of that work has been in complex hosted auction platforms, professional Joomla! deployments and extension development and sales.

As such, Cameron has acquired a deep technical skill-set, a sensitivity to client needs, and the ability to produce anything those clients can visualize.

Everyday, he actively seeks out and becomes familiar technologies that will give MMI clients maximum return for their web development and general e-presence dollar.

magneticmerchandising.com
More in this category: Customizing Head tags Joomla... »