Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joomla 4.3.3 Alternate Layouts don't work when there is a subline in the template #41270

Closed
coolcat-creations opened this issue Jul 27, 2023 · 20 comments

Comments

@coolcat-creations
Copy link
Contributor

coolcat-creations commented Jul 27, 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.

@richard67
Copy link
Member

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.

@brianteeman
Copy link
Contributor

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

@coolcat-creations
Copy link
Contributor Author

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

@brianteeman
Copy link
Contributor

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

@brianteeman
Copy link
Contributor

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

@coolcat-creations
Copy link
Contributor Author

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

@brianteeman
Copy link
Contributor

well its something in your code and not a core issue

@brianteeman
Copy link
Contributor

@richard67
image

@coolcat-creations
Copy link
Contributor Author

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

@coolcat-creations
Copy link
Contributor Author

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

@chmst
Copy link
Contributor

chmst commented Jul 27, 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');

@brianteeman
Copy link
Contributor

@chmst thats what I wrote #41270 (comment)

@coolcat-creations
Copy link
Contributor Author

@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.

@brianteeman
Copy link
Contributor

I just repeated it from scratch with no problem at all

@coolcat-creations
Copy link
Contributor Author

coolcat-creations commented Jul 27, 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.

@hendrikbehncke
Copy link
Contributor

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']
    );
}

@brianteeman
Copy link
Contributor

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

@hendrikbehncke
Copy link
Contributor

hendrikbehncke commented Jul 28, 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);

coolcat-creations added a commit to coolcat-creations/joomla-cms that referenced this issue Jul 28, 2023
@brianteeman
Copy link
Contributor

Should be closed as there is a PR

@alikon
Copy link
Contributor

alikon commented Aug 10, 2023

please test #41274

@alikon alikon closed this as completed Aug 10, 2023
laoneo pushed a commit that referenced this issue Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants