Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Problem in linking footer

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

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

Page: 1
Go to End
Author Topic: 6390 Views
  • Mayuri
    Avatar
    Community Member
    19 Posts

    Problem in linking footer Link to this post

    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

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Problem in linking footer Link to this post

    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.

  • spenniec
    Avatar
    Community Member
    37 Posts

    Re: Problem in linking footer Link to this post

    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?

  • Mayuri
    Avatar
    Community Member
    19 Posts

    Re: Problem in linking footer Link to this post

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

    6390 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.