Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Secondary Menu?


Go to End


20 Posts   13264 Views

Avatar
areikiera

Community Member, 26 Posts

13 February 2008 at 4:25am

Hi everyone!

I'm creating a site for a client using Silverstripe, but I'm still unclear about the limitations. I've completed the tutorials and feel that I have a pretty good grip on it, but not quite yet on manipulating the code to extend the site a little.

Menus seem to only work in levels... one menu, and the submenus associated with each menu item. I need a secondary menu that is completely unaffected by the first, but still managable in the CMS. This menu will be the same on every page, regardless of how deep you are in the primary menu structure. I call them my utility links (sections like: contact us, employment, customer login). There are simply too many links to include them all in the primary menu.

How can I create this separate secondary menu, and have it be updatable in the CMS?

Thanks for any replies!

(Also, when navigating the main menu structure, is there a way to dynamically mark both the menu1 link AND the menu2 - submenu section link as "current" at the same time?)

Avatar
Wojtek

Community Member, 149 Posts

13 February 2008 at 7:42am

Edited: 13/02/2008 7:43am

>> (Also, when navigating the main menu structure, is there a way to dynamically mark both the menu1 link AND the menu2 - submenu section link as "current" at the same time?)

the selected menu1 item is marked as "section" class, the selected menu2 item is marked as "current" class, and the rest is marked as "link"... why not assign 'section' the same attributes as 'current' has?

Avatar
SilverRay

Community Member, 167 Posts

13 February 2008 at 3:06pm

Edited: 13/02/2008 3:08pm

About having a standard list of links in every page:

1. Make a dataobject for these links so it becomes a table in the database. Let's call these links 'Shortcuts' for instance. So what you would do is create a ShortCut.php file (goes in your code directory) in which you a) define the variables for your links, b) that you want to manage it as a many_many array, and c) define the fields for the popup window to edit the links. Code for ShortCut.php could look like so: http://pastie.caboo.se/151301

2. Create a page type for managing the actual 'column' of links in the cms, let's call this 'ShortCutColumn.php (also goes in code dir). You would create a page in the cms based on this page type, in which there will be an extra tab to manage the list of urls. Code for this page type would look like this: http://pastie.caboo.se/151304

3. Create an include file (.ss file to use as an include in other .ss template files, goes in templates/Includes) to contain these links, in which you are going to use a control block for showing them. The control block would look something like this:

<% control Page(url-of-your-shortcuts-page) %>
<ul>
<% control SCSection1 %>
<li><a href="$ShortCutLocation" title="$ShortCutTitle">$ShortCutName</a></li>
<% end_control %>
</ul>
<% end_control %>

where url-of-your-shortcuts-page is the url of the page you made in the cms, based on the ShortCutColumn page type, in other words the page that you use to manage the list of links.

Together with the tutorials on the Silverstripe site, this should do the trick. Does it? ;)

I hope I didn't make too many typo's (better check for them). Perhaps there's a better way, but this is how I do it currently.

Avatar
areikiera

Community Member, 26 Posts

14 February 2008 at 3:20am

Thanks for the replies!

You can probably tell I'm new at this, and I really really appreciate the help.

Thanks wojtek for the tip! I'm surprised I didn't notice that when I was looking at the source code!

And SilverRay, I'm gonna give that a try today. Thanks for the detail you included. I'm still in need of step-by-step instructions at this point, and I think this will really help me!

Thanks again!

Avatar
areikiera

Community Member, 26 Posts

14 February 2008 at 5:11am

Edited: 14/02/2008 6:17am

I've created the ShortCut.php and ShortCutColumn.php pages, but when I rebuild the database, nothing happens. I don't think the tables have been created in the database, and the new page type from ShortCutColumn.php doesn't show up in the CMS.

Any help?

Also, the url-of-your-shortcuts-page, would that simply be "/ShortCut/"? Or would it be more like "themes/theme_name/ShortCut/"? I'm not sure I understand how links work in Silverstripe right now either.

When I include the includes/ShortCut.ss file, will I just type "<% include ShortCut %>, or do I need to be more specific?

Thanks again in advance!

I'll probably be running through the tutorials again as I go... sigh : )

Avatar
areikiera

Community Member, 26 Posts

14 February 2008 at 8:26am

I've been huffing away at this and I've discovered that when I rebuild the database, it doesn't seem to even look at the code folder. The theme that I copied and modified (thanks wojtek), didn't include the 'code' folder originally, I created it.

Is there a file I need to edit to get silverstripe to look at the 'code' folder when I rebuild the database?

(The 'code' folder is located in the same folder as the 'templates' folder.)

Avatar
SilverRay

Community Member, 167 Posts

14 February 2008 at 1:36pm

Edited: 14/02/2008 1:41pm

Maybe it is better if you move your complete site to the 'mysite' folder, just to try things out. Then in the _config.php file inside the 'mysite' folder you would say:

global $project;
$project = 'mysite';

above the database login info.

In your mysite folder you would have the following directories:

code
css
images
javascript
templates

which need to have all necessary files in them. For some info about this subject, see here:

http://doc.silverstripe.com/doku.php?id=themes:developing#reference

You're right about how to use include, but the name should be whatever url you have designated to the page in the cms you use to manage the links (so not necessary 'shortcut', it could be whatever name in the format 'whatever/'. The page only exists in the cms and would be based on the ShortCutColumn type. The template .ss file you have created to include in other pages only is necessary as a template to generate the html for showing the links by way of a control block).

I can imagine this is confusing, so I would certainly redo all tutorials and understand them before doing this link list thing perhaps... (It helped me at the time for sure!)

Avatar
Willr

Forum Moderator, 5523 Posts

14 February 2008 at 2:03pm

I've been huffing away at this and I've discovered that when I rebuild the database, it doesn't seem to even look at the code folder. The theme that I copied and modified (thanks wojtek), didn't include the 'code' folder originally, I created it.

You didnt happen to create the code folder in the themes folder did you? The Themes folder should contain the css/ images/ templates/ folder and nothing else. The code files should all be in the code folder under mysite

Go to Top