How to add a second view to a component (so that it is visible as an option when adding to a menu in administration) Topic is solved
Moderators: ooffick, General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
-
- Joomla! Apprentice
- Posts: 15
- Joined: Tue May 07, 2024 5:12 pm
How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
Hello,
I followed https://docs.joomla.org/J4.x:Developing ... _Site_Part and created a HelloWorld component in J4.
I am now trying to add a second view called Hello2 but this second view does not appear in the admin part in Joomla menu system as a link target (e.g. when linking this component to a menu). The first view will appear as an option but the second one does not. I am attaching the component. I am probably missing some detail. Any help appreciated.
Thanks,
Jan
I followed https://docs.joomla.org/J4.x:Developing ... _Site_Part and created a HelloWorld component in J4.
I am now trying to add a second view called Hello2 but this second view does not appear in the admin part in Joomla menu system as a link target (e.g. when linking this component to a menu). The first view will appear as an option but the second one does not. I am attaching the component. I am probably missing some detail. Any help appreciated.
Thanks,
Jan
You do not have the required permissions to view the files attached to this post.
- Webdongle
- Joomla! Master
- Posts: 44175
- Joined: Sat Apr 05, 2008 9:58 pm
Re: How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
Same principle as https://docs.joomla.org/J3.x:Layout_Ove ... Menu_Items
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
-
- Joomla! Apprentice
- Posts: 15
- Joined: Tue May 07, 2024 5:12 pm
Re: How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
Thanks for the link. Indeed, the same principle of adding an XML file for the menu item description of the "Hello" or "Hello2" page template (view) as with articles. It, however, still does not work for me.
Having
makes the view available directly via a link, e.g. http://localhost/index.php?option=com_h ... iew=hello2.
So far so good.
Now adding a should create a menu item description which is then available in Joomla admin back-end but this only works for the first "Hello" view but not for the second view "Hello2".
I am attaching my simple component to this post. Any hint appreciated. Thanks.
Having
Code: Select all
com_helloworld/site/src/View/Hello2/HtmlView.php
com_helloworld/site/tmpl/hello2/default.php
So far so good.
Now adding a
Code: Select all
com_helloworld/site/tmpl/hello2/default.xml
I am attaching my simple component to this post. Any hint appreciated. Thanks.
You do not have the required permissions to view the files attached to this post.
- Webdongle
- Joomla! Master
- Posts: 44175
- Joined: Sat Apr 05, 2008 9:58 pm
Re: How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
You have no xml or php files for your alternative layouts. Without those they will not show up as a choice in the menu edit screen.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
-
- Joomla! Hero
- Posts: 2990
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
Apparently, this has to be unique:
If you change it to "Hello World 2" or something else that's different from the first layout, it will appear.
Code: Select all
<layout title="Hello World!">
- Webdongle
- Joomla! Master
- Posts: 44175
- Joined: Sat Apr 05, 2008 9:58 pm
Re: How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
And the xml and php files should match the unique name. I have done it sometime ago (following the page I linked to) as a Template override but not as a second view in a component.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
- ceford
- Joomla! Hero
- Posts: 2794
- Joined: Mon Feb 24, 2014 10:38 pm
- Location: Edinburgh, Scotland
- Contact:
Re: How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
The tutorial you were following is incomplete. You could try following this article:
https://jdocmanual.org/jdocmanual?manua ... started.md
It follows a take it apart to see how it works approach rather than a build it step by step approach. It has two sub-menu items in the Administrator menu.
https://jdocmanual.org/jdocmanual?manua ... started.md
It follows a take it apart to see how it works approach rather than a build it step by step approach. It has two sub-menu items in the Administrator menu.
-
- Joomla! Apprentice
- Posts: 15
- Joined: Tue May 07, 2024 5:12 pm
Re: How to add a second view to a component (so that it is visible as an option when adding to a menu in administration)
Thanks for all the helpful replies and links. The problem was the layout title that apparently must be unique (@sharkyKZ thanks for the tip).
With e.g.
the menu item for the "Hello2" view will appear. Thanks!!
With e.g.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="Hello World 2!">
<message><![CDATA[My second Joomla! page]]></message>
</layout>
</metadata>
You do not have the required permissions to view the files attached to this post.