Keyword

K2 Power Tip: Use PHP Includes to Render Override Files

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
7 years 8 months ago #156678 by Joe Campbell
Using K2 overrides can do wonders for website creation, but prove challenging when have many overrides (each with many elements).

To reduce the number of override files you can use PHP includes.

For example, I have a Quotes section for which I display the list page in a Pinterst-like manner. It's the only section of my website that is like that. But the item page is the same as every other section. So in this case, I use a PHP include to render the item.php file housed in my primary override.

Best of all, you can use this method for each and every override file (category.php, category_item.php, tag.php, etc.)

Here's the code, simply change the areas denoted in red:

<?php include($_SERVER.'/templates/TEMPLATE-NAME/html/com_k2/OVERRIDE-FOLDER/item.php'); ?>

Happy K2 Coding :)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #156684 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 Power Tip: Use PHP Includes to Render Override Files
Actually Yiota wrote a nice similar blog post about it a while back
I'm sure you've read it but it'll post it anyway :)

www.joomlaworks.net/blog/item/194-k2-inheritance-sub-templating

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
7 years 8 months ago #156688 by Joe Campbell
WOW - I never realized this...

You can also decide which elements your sub-templates have in common, whether this is the category (category.php), tag (tag.php), user (user.php) or item page (item.php) with the default and include only the different file(s) in your sub-template.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #156721 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 Power Tip: Use PHP Includes to Render Override Files
Yes, it makes maintenance much easier.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum