No Code Attached Yet
avatar coolcat-creations
coolcat-creations
27 Jul 2023

Steps to reproduce the issue

have a template named yourtemplate_child

make a copy of
html/com_content/category/default.php
html/com_content/category/default.xml
html/com_content/category/default_articles.php
html/com_content/category/default_children.php

rename them and put in this template an alternate layout for a category list:
html/com_content/category/mylayout.php
html/com_content/category/mylayout.xml
html/com_content/category/mylayout_myarticles.php
html/com_content/category/mylayout_mychildren.php

In mylayout.php change articles to myarticles (I did that but did not mentio in the test instructions)
Change something in the _myarticles file or put a die(); at the top to see if your template is loaded.
Change the layout title in the mylayout.xml so you recognize it in the menu item types overview

Create a new menu item and select my layout as a menu item type

Expected result

your alternate layout is loaded when you selected it as a menu type

Actual result

Several issues here:

  1. the default view is loading a layout that needs to be adjusted as well. and no matter how your _articles and _children files are named it will always load children

so a step in between would be to create a file named:
/templates/yourtemplate/html/layouts/joomla/content/category_mylayout.php
and rename also the subtemplates in the $displayData->loadTemplate call

But even if you do this - you will get a 500 Error when your template has an underscore in it.

If you move the whole structure to a template without underscore it works.

System information (as much as possible)

I tried to debug within the libraries/src/MVC/View/HtmlView.php file and when I print out the path Joomla is looking for I get:

mytemplate_nlh_nlh_nlh/html/
altough my templates name is only mytemplatee_nlh, so I think it has something to do with the underscores in the template name.

avatar coolcat-creations coolcat-creations - open - 27 Jul 2023
avatar joomla-cms-bot joomla-cms-bot - change - 27 Jul 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Jul 2023
avatar richard67
richard67 - comment - 27 Jul 2023

As far as I know this is expected behaviour, and it was always like that. There might be even some tooltip in the template name field telling that only alpha-numeric characters and dashes are allowed.

If someone else confirms this (I don't expect myself to be perfect), I will close this issue as expected behaviour.

avatar brianteeman
brianteeman - comment - 27 Jul 2023

I have a site using a child template cassiopeia_leadershape
As you can see from the screenshot below I have lots of blogcategory overrides that have been renamed as something else and also have an xml file

image

avatar coolcat-creations
coolcat-creations - comment - 27 Jul 2023

@brianteeman ok so the issue is not coming from the underscore? Strange :-/

avatar brianteeman
brianteeman - comment - 27 Jul 2023

silly question but in html/com_content/category/mylayout.php did you update the loadTemplate for your new names
$this->loadTemplate('myarticles')

avatar brianteeman
brianteeman - comment - 27 Jul 2023

It can NOT come from the underscore because that is how child templates are created by joomla

avatar coolcat-creations
coolcat-creations - comment - 27 Jul 2023

yes I did - the error dissapears when I move the complete structure
from the child to the main - so something else is interfering

avatar brianteeman
brianteeman - comment - 27 Jul 2023

well its something in your code and not a core issue

avatar brianteeman
brianteeman - comment - 27 Jul 2023
avatar coolcat-creations
coolcat-creations - comment - 27 Jul 2023

Not in my code but maybe some exception for not child template templates with underscore - i will investigate further

avatar coolcat-creations
coolcat-creations - comment - 27 Jul 2023

@brianteeman and @richard67 thanks for testing - I will report back what the issue was.

avatar chmst
chmst - comment - 27 Jul 2023

@coolcat-creations if you make a template override for any default and call it mylayout.php
then this script still contains a statement like

echo $this->loadTemplate('item');

it will load mylayout_item.php if yo did not override this statement to make

echo $this->loadTemplate('myitem');

avatar brianteeman
brianteeman - comment - 27 Jul 2023

@chmst thats what I wrote #41270 (comment)

avatar coolcat-creations
coolcat-creations - comment - 27 Jul 2023

@brianteeman @chmst I wrote both correctly in the layout. As said it works as indented when I move it in another template. there must be something else interfering. I am investigating further.

avatar coolcat-creations coolcat-creations - change - 27 Jul 2023
The description was changed
avatar coolcat-creations coolcat-creations - edited - 27 Jul 2023
avatar brianteeman
brianteeman - comment - 27 Jul 2023

I just repeated it from scratch with no problem at all

avatar coolcat-creations coolcat-creations - close - 27 Jul 2023
avatar coolcat-creations
coolcat-creations - comment - 27 Jul 2023

I just tested with a not template and named it test_test and it worked too. So the issue is not in the core but something in the maintemplate probably. Thank you all for testing.

avatar coolcat-creations coolcat-creations - change - 27 Jul 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-07-27 18:00:35
Closed_By coolcat-creations
avatar hendrikbehncke
hendrikbehncke - comment - 28 Jul 2023

The problem is because the child template folder name begins with the same name as the template (e.g. cassiopeia and cassiopeia_child).

Here is a fix for it in libraries/MVC/HtmlView.php on line 377
Add a directory separator to prevent replacing the template path twice.

// Change the template folder if alternative layout is in different template
if (isset($layoutTemplate) && $layoutTemplate !== '_' && $layoutTemplate != $template->template) {
    $this->_path['template'] = str_replace(
        JPATH_THEMES . DIRECTORY_SEPARATOR . $template->template . DIRECTORY_SEPARATOR,
        JPATH_THEMES . DIRECTORY_SEPARATOR . $layoutTemplate . DIRECTORY_SEPARATOR,
        $this->_path['template']
    );
}
avatar brianteeman
brianteeman - comment - 28 Jul 2023

so why is it working perfectly for me (and others)

avatar hendrikbehncke
hendrikbehncke - comment - 28 Jul 2023

so why is it working perfectly for me (and others)

This depends on how many subtemplates are loaded, therefore the HtmlView::loadTemplate() method is called multiple times.

$this->subtemplatename = 'myarticles';
echo LayoutHelper::render('joomla.content.category_default', $this);
avatar coolcat-creations coolcat-creations - change - 28 Jul 2023
Status Closed New
Closed_Date 2023-07-27 18:00:35
Closed_By coolcat-creations
avatar coolcat-creations coolcat-creations - reopen - 28 Jul 2023
avatar brianteeman
brianteeman - comment - 10 Aug 2023

Should be closed as there is a PR

avatar alikon alikon - change - 10 Aug 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-08-10 08:17:17
Closed_By alikon
avatar alikon alikon - close - 10 Aug 2023
avatar alikon
alikon - comment - 10 Aug 2023

please test #41274

Add a Comment

Login with GitHub to post a comment