Learning How To Configuration Sub Template In K2

As you know, Joomla 1.5 is an MVC content management system and provides you with the means to “override” default HTML layouts within your template’s folder. All you need to do is to copy the “tmpl” folder of a component’s view within your Joomla! template’s /html/com_componentName/ folder. In K2 version 1.0.x, it’s limiting for the potential of this component if you wanted to use K2 for blog, catalog, or magazine,… simpler compared to current Joomla! templating: all you have to do to override K2’s views is COPY THE CONTENTS of the folder /components/com_k2/templates/and PASTE it into /templates/YOURJOOMLATEMPLATE/html/com_k2/.

After you copy this folder over to your /templates/ YOURJOOMLATEMPLATE/ html/com_k2 / folder, you will see some “views” are right at the root of that folder (e.g. generic.php or user.php) and some other views are located within a subfolder, called “default“. They’re located in: /templates/YOURJOOMLATEMPLATE/html/com_k2/

The “views” that are right at the root of that folder can’t be themed into variations and this is normal, so you don’t need to have different layouts for the registration page or the user page or the page that shows search results from K2 content! If you wanna override K2, just simply edit these “views“.

The “views” that are located within the folder “default” are the ones that can be themed into variations and you can selected these “variations” from K2’s backend, when editing categories or “menu items” to K2 categories.
Example: You’re inside /templates/YOURJOOMLATEMPLATE/html/com_k2/. if you copy the folder “default” and change its name to “blog”, this folder contains views to the item and categories will then be picked up by K2, without having to exist inside /components/com_k2/. Repeat the process and you can create groups of “views” (sub-templates in K2 lingo) which can then be used for different parts of your K2 based site. If you want to edit sub-template, you can edit the files contained in each folder. And if you edit the item.php view in the folder “blog”, for example, then only the categories or menu items using this sub-template will pick up your changes.

If your website had 3 3 major areas, a news section, a knowledge base and a catalog of products, you ca create 3 copies of the “default” folder, rename them, then you create your create each parent category, assigning the respective sub-template each time. Now, you can edit each sub-template and get the desired layout for your Joomla! site.

As you can imagine this opens a whole new way of skinning K2 based Joomla! websites as you only have one component yet different views per functionality. So your K2 blog is different to your K2 catalog or your K2 news/magazine section and so on.

FILE & FOLDER PATH EXAMPLES IN K2 MVC TEMPLATING

Within the component Within our template
/components/com_k2/templates/ /templates/YOURTEMPLATE/html/com_k2/
/components/com_k2/templates/user.php /templates/YOURTEMPLATE/html/com_k2/user.php
/components/com_k2/templates/default/item.php /templates/YOURTEMPLATE/html/com_k2/default/item.php
/components/com_k2/templates/newsubtemplate/category.php /templates/YOURTEMPLATE/html/com_k2/newsubtemplate/category.php
(does not have to exist) /templates/YOURTEMPLATE/html/com_k2/differentSubTemplateNotExistingInComponent/category.php
Thanks for your reading, and if you have any questions with this blog, don’t hesitate to let us know by leaving a comment.
Rate for post
LT Digital Team (Content & Marketing)
Latest posts by LT Digital Team (Content & Marketing) (see all)
All-In-One Membership Access PRO version of all 500+ all Joomla! templates and WordPress themes. Just from $7.25/MO Learn more
🎉 Merry xMas & Happy New Year sale! Grab 50% Off for everything on today, don't miss it. Coupon code: XMASNEWYEAR Redeem Now