2

I want to use a template override for Articles in Joomla, therefore I am using

mytemplate/html/com_content/article/default.php

If I change anything in this file the changes do appear. But as I want to use an extra .php-file f.e.

mytemplate/html/com_content/article/alternativeLayout.php 

I am facing a problem. Because although I can select this layout on the article settings page - any Changes I make do not appear and still the default.php is used.

Any ideas what I am doing wrong?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Ripei
  • 432
  • 2
  • 8
  • 19

4 Answers4

6

In order for an alternative layout to be used, two conditions must be met -

  1. You must select the layout in the article parameters
  2. No menu item can exist for this item - the layout selection of the menu item will override the selection in the article parameters

It sounds like your problem is with #2.

EDIT Duh, I missed the key part of using alternate layouts. In order to be able to use an alternate layout with a menu item, you have to create an alternatelayout.xml file and place it in the override folder. This will give you an additional menu item option that you select when creating your menu item. You should be able to copy the defailt.xml file and edit it for the new layout.

Brent Friar
  • 10,588
  • 2
  • 20
  • 31
  • Hey, thanks for the response. Yeah it sounds like #2. But why is this so? What if I want a menu-item to linkt to this article and I also want an article-layout override... is there really no way to achive this? Because isn't it stupid to not make this possible? ;)^^ – Ripei Apr 26 '11 at 23:01
  • Sure, you set the correct template override in the menu item. Menu items will always override the settings in an article by design, so if it exists, the article parameter will be ignored. – Brent Friar Apr 27 '11 at 00:16
  • Well this sounds logical :) Can you also tell me where/how I can set the correct template override in the menu item? I am sorry but wasn't able to figure this out. – Ripei Apr 27 '11 at 10:11
  • Hmm. In the menu item you can select the template style, but it appears that it is not picking up any of the alternate layouts, just the default. I'll need to look in to the code to see what that is. – Brent Friar Apr 27 '11 at 13:20
  • yeah and I also couldn't figure out where i can change the php-code of the new template-style (which i created via the admin backend)? – Ripei Apr 27 '11 at 15:16
  • Unfortunately there is no way to change a template style's code. Those are meant to offer multiple versions of the same template with different parameters set. It's only changing the template parameters. – Brent Friar Apr 27 '11 at 19:36
  • Just to be sure. I have to create f.e. the "myNewLayout.php" which i get from '/html/components/com_content/views/article/tmpl' I put this and the renamed "myNewlayout.xml" which I also get from this folder into: 'mytemplate/html/com_content/article' and this should enable me to select it in the menu-item-backend? Because I assume that I did get sth. wrong^^ – Ripei Apr 27 '11 at 20:08
  • Correct, you have to have a PHP and XML file with the same name. Then you will have an additional Menu Item Type to select from - when you click the select button, under Articles you will see the alternate layouts listed there. – Brent Friar Apr 27 '11 at 21:33
  • hrmpf.. I am sorry for asking again, but I am afraid I still can't get it working. When I do have both files in /com_content/article of my layout. There is no additional layout selectable on the menu-item-page. And also on the article-page at the backend I am not further more able to select my new layout. – Ripei Apr 27 '11 at 21:57
  • 2
    On the menu item page, next to the Menu Item Type there is a select button, click that to see all of the options. Under Article you should see the new alternate layout. – Brent Friar Apr 27 '11 at 23:27
2

I created a visual tutorial for this as it was driving me mad for about two days until I figured out how to actually work it. You can find it here: Joomla custom article template

I hope it helps others solve this faster than I did :-)

PS: all the credit for the article goes to Brent!!

nicky
  • 787
  • 2
  • 12
  • 27
1

the name of the files must be the same. The override must have the name "default". So its:

/yourTemplate/html/com_content/article/default.php
/yourTemplate/html/com_content/article/default.xml
/yourTemplate/html/com_content/article/default_links.php

had exactly the same problem, this solution solved it.

Pabzt
  • 496
  • 4
  • 13
0

Also, note that any override filenames must be lower case. For example, "AboutPage.php" won't work.

Pete
  • 21
  • 2