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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

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

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

Problem in linking footer


Go to End


4 Posts   6651 Views

Avatar
Mayuri

Community Member, 19 Posts

13 May 2008 at 2:46pm

Hi all,

I wants to add links to footer of my website. I have created footerMenu.php like;
<?php
/**
* Defines the FooterMenuPage page type
*/
class FooterMenu extends Page {
static $db = array(
);
static $has_one = array(
);
static $allowed_children = array('Page');
}
class FooterMenu_Controller extends Page_Controller {
}
?>

And added footerMenu.ss in includes;

<% if FooterMenu %>
<ul id="FooterMenu">
<% control FooterMenu %>
<li class="$LinkingMode"><a href="$Link" title="Go to the $Title page">$MenuTitle</a></li>
<% end_control %>
</ul>
<% end_if %>

I also had added tab in behaviour of page like show only in footer menu and trying to call in page.ss under div footer like $footermenu but it didn’t work at all for me.

Can anyone guide me where I am making mistake? What I need to add more. Plz help me I am not too good at PHP.

Thanks in advance

Avatar
Sam

Administrator, 690 Posts

13 May 2008 at 4:33pm

I don't know if a different page type is what you want here. It might be better to create a page with a particular URL; for example, footer-menu. Uncheck "Show in menus" on that page so that it doesn't show in the your main nav, and put all your footer items under that.

You can then put <% control ChildrenOf(footer-menu) %> into your Page.ss template to get the children of that page listed as their own navigation menu.

Avatar
spenniec

Community Member, 37 Posts

13 May 2008 at 7:43pm

Edited: 13/05/2008 8:07pm

I took the following approach to footer links;

Create a file called FooterLinks.php and place it under mysite/code with the contents - http://pastie.caboo.se/195936
Note the line 'MyPage' => 'Page', if you want the Footer tab to appear on every Page then it will.

In Page.php add

static $many_many = array(
'FooterLinks' => 'FooterLink'
);

and add the following to function getCMSFields() in Page.php

$linksTablefield = new ManyManyComplexTableField(
$this,
'FooterLinks',
'FooterLink',
array(
'LinkText' => 'LinkText',
'LinkURL' => 'LinkURL',
'LinkID' => 'LinkID',
),
'getCMSFields_forPopup'
);
$linksTablefield->setAddTitle( 'A Link' );
$fields->addFieldToTab( 'Root.Content.Footer', $linksTablefield );

when you rebuild database you will have the tab for adding/removing and enabling footer links in the CMS.

You then need to display it in the template.
For this you could create a Footer.ss file and place it in the includes directory
This could have the following contents

<% if FooterLinks %>
<ul>
<% control FooterLinks %>
<li><a href="$LinkURL" id="$LinkID">$LinkText</a></li>
<% end_control %>
</ul>
<% end_if %>

You then need to place <% include Footer %> in the main Page.ss
You can then style the list items as required.

I guess I could put this in as a recipe but it wasn't immediately obvious how I create a page in the docos. Anyone point me in the right direction?

Avatar
Mayuri

Community Member, 19 Posts

14 May 2008 at 10:28am

Thank you both of you for your suggestions.
It worked easily with the option sam has provided. Thank you..........