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

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

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.
Post Reply
JanoD
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
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)

Post by JanoD » Sat May 11, 2024 10:17 am

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
You do not have the required permissions to view the files attached to this post.


JanoD
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
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)

Post by JanoD » Sat May 11, 2024 9:21 pm

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

Code: Select all

com_helloworld/site/src/View/Hello2/HtmlView.php
com_helloworld/site/tmpl/hello2/default.php
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

Code: Select all

com_helloworld/site/tmpl/hello2/default.xml 
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.
You do not have the required permissions to view the files attached to this post.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44136
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)

Post by Webdongle » Sat May 11, 2024 10:48 pm

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

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2954
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)

Post by SharkyKZ » Sun May 12, 2024 7:49 am

Apparently, this has to be unique:

Code: Select all

<layout title="Hello World!">
If you change it to "Hello World 2" or something else that's different from the first layout, it will appear.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44136
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)

Post by Webdongle » Sun May 12, 2024 9:45 am

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

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2750
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)

Post by ceford » Sun May 12, 2024 5:12 pm

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.

JanoD
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
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)

Post by JanoD » Mon May 13, 2024 7:19 am

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.

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>
the menu item for the "Hello2" view will appear. Thanks!!
com_helloworld_multiple_views_available_as_menu_items.png
You do not have the required permissions to view the files attached to this post.


Post Reply

Return to “Joomla! 4.x Coding”