Prevent menu link for certain layouts

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.
Locked
User avatar
dodlee
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Sun Dec 10, 2006 8:20 am

Prevent menu link for certain layouts

Post by dodlee » Wed Nov 14, 2007 10:11 am

Hi,
I'm writing a component which has an advanced search page.
So I created a 'search' view and model, and I figured the view will have two layouts: one for the search form and one for the search results.

Problem is, when I want to add a menu item in the backend, I automatically have the option to add a link to the search results layout, even tough this link is meaningless (linking to search results with no search parameters).

Is there a way to prevent a layout from appearing in the menu->add item page, or maybe my code is not structured correctly?

Thanks!
Last edited by dodlee on Tue Dec 11, 2007 2:36 pm, edited 1 time in total.

User avatar
dodlee
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Sun Dec 10, 2006 8:20 am

Re: Prevent menu link for certain layouts

Post by dodlee » Tue Dec 11, 2007 2:34 pm

Ok, guess I'll answer myself.
So, to prevent a layout from automatically appearing as a menu target option, the xml file for this layout must include the tag:

Code: Select all

<layout hidden="true" />
This XML file is a file with the same name as the layout located with the layout file.
So, assuming the layout will have no options and parameters, the xml file will look like this:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<metadata>
	<layout hidden="true" />
</metadata>
An example from the core files is \components\com_content\views\article\tmpl\pagebreak.xml

Hope this could help somebody

Gooday

Opie
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 163
Joined: Thu Jun 22, 2006 7:32 pm
Contact:

Re: Prevent menu link for certain layouts

Post by Opie » Tue Dec 11, 2007 2:41 pm

Thanks for answering yourself.  :D

I was needing this the other day, but I was sidetracked and never finished looking into it.

Thanks again.
http://springhillalumni.org • Springhill High School Alumni Association
http://bentonhighalumni.com • Benton High School Alumni

User avatar
dodlee
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Sun Dec 10, 2006 8:20 am

Re: Prevent menu link for certain layouts

Post by dodlee » Thu Dec 13, 2007 9:04 am

Happy to be of service :)

User avatar
tfuller
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 218
Joined: Tue Sep 20, 2005 11:30 pm
Location: Oregon
Contact:

Re: Prevent menu link for certain layouts

Post by tfuller » Thu Dec 13, 2007 6:56 pm

I had a similar problem but fixed it in another way. If you have a view that goes to a list, and another that goes to the details of an item from that list, you may wish the details view to be visible and create the ability to link to a specific item directly, rather than going to the list first.

To do that you need to use elements. Look at the Banners or Contact components for an idea how that works. Generally you set up an elements folder on your admin side and create a php file that does the db lookup and creation of things like a drop down list of items - the name is based on the parameter you then put in an xml file you put in the view/tmpl folder called default.xml.

The code could be like:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: default.xml tf 12-11-2007 $ -->
<metadata>
	<layout title="Single Study Layout">
		<message>
			<![CDATA[Create a link to a single study's details]]>
		</message>
	</layout>
	<state>
		<name>Single Study Layout</name>
		<description>Choose a single study to link to</description>
		<url addpath="/administrator/components/com_biblestudy/elements">
			<param name="id" type="studiesview" default="" label="Select a Study" description="The study to link to" />
		</url>
	</state>
</metadata>
"id" is the name of the field you are going to choose from the db lookup, "studiesview" is the file that the site will look for in the elements folder of the admin side. Again, check out one of the core components for how to do this in particular.

These xml files also allow you to restrict what if any parameters show up when an admin creates a menu item for the component. If you put an xml file in the view folder on the site side called metadata.xml, it can have just something like this as code:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: metadata.xml 2007-12-11 $ -->
<metadata>
</metadata>
Then put a default.xml file into the details view tmpl folder with content that is similar, then when the admin creates a menu item he/she won't have any parameters to choose from.
Author of component Joomla Bible Study:
http://www.JoomlaBibleStudy.org


Locked

Return to “Joomla! Coding 101”