Joomla Custom Article Template With Menu Link

Having seen this question asked a lot, this tutorial will focus on creating custom templates for articles in Joomla where the article is linked too via a menu. The problem: Intuitively, most people expect that when you assign an article an alternative layout, it changes the way that article would appear. Sadly, it does not work that way if you link to that article through a menu on your page. We will assume that you have created a custom template and that it is called ‘mytemplate’, located under /templates/mytemplate/. You should have a directory called html in your template folder. Inside that folder you will need the following structure: com_content/articles (or in a more complete form: /templates/mytemplate/html/com_content/articles). If you do not have that structure in place then simply create the directories. This is where the custom template that you create will be placed.

Once your directory structure is complete, you need to copy over the default joomla template and from that point on you can edit to your heart’s desire. The two files you need to copy are called default.php and default.xml and they are located in /components/com_content/views/article/tmpl. Copy both those files into your /templates/mytemplate/html/com_content/articles directory.

Rename the two files you just moved into your template directory. In line with this tutorial we will call them mytemplate.php and mytemplate.xml. It is extremely important that you have both the php and the xml file and that they have the same name. Without the xml file you will not be able to select the template in the menu editor.

Edit the mytemplate.xml file so that it looks something like this:
<layout title="mytemplate" option="mytemplate">
<help key = "JHELP_MENUS_MENU_ITEM_ARTICLE_SINGLE_ARTICLE"  />
<message>
<![CDATA[com_content_article_view_default_desc]]>
</message>
</layout>
The layout title and option change the name of your template in the dropdown at the menu editor (see below).   To implement your hard work, add a new menu item. Select a menu item type. And under articles you should see your new template style You’re done. Congratulations! You can now edit the mytemplate.php file as you desire and you will see the changes on your website.

Comments are closed.