Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » creating a new tab with LeftAndMain that is just a frame underneath

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: 1706 Views
  • Matt Hardwick
    Avatar
    Community Member
    61 Posts

    creating a new tab with LeftAndMain that is just a frame underneath Link to this post

    I know that this is possible as people have talked about this in the forums, just can't find any notes on it; I read http://doc.silverstripe.com/doku.php?id=private:tutorial:creating-a-module but didn't really get very far.

    We have a couple of in house and commercial web applications. We access these with a list that links to them all on its own address www.domain.com/intranet and links from that page go to intranet/membership, intranet/programming, intranet/playlists.

    I want to create a new tab inside the CMS that is called Intranet and just loads a frame underneath that contains /intranet .

    This way users only need to go to one address.

    Can someone help or point me in the right direction?

    Thanks in advance.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: creating a new tab with LeftAndMain that is just a frame underneath Link to this post

    Hey Matt,

    To create the link, you need to add a rule to Director and a menu item to LeftAndMain. In your _config.php, add the following lines:

    LeftAndMain::add_menu_item(
       'intranet',
       _t('LeftAndMain.INTRANET','Intranet'), // just in case you want to translate it!
       'intranet',
       'IntranetPlanel'
    );
    Director::addRules(100, array(
       'intranet/$Action' => 'IntranetPanel',
    ));

    In your code directory, create a new file "IntranetPanel.php" and save the following code:

    class IntranetPanel extends LeftAndMain {

       public function init() {
          
          parent::init();

       }
       
       public function Link($action = null) {
       
          return "intranet/$action";
          
       }
    }

    Finally you need to make a few templates.

    Create a new empty file "IntranetPanel_right.ss" and place it in your Includes directory. It will contain your iframe, which you will need to style. For example:

    <iframe style="width: 100%; height: 100%;" src="http://intranet/"></iframe>

    Copy LeftAndMain.ss to your templates directory and rename it "IntranetPanel.ss".

    Since we don't need a left tree element, remove the line:

    <div id="left" style="float:left">
          $Left
    </div>

    Finally, modify the div with the id 'right' to read:

    <div class="right" style="width: 98%" id="right">
          $Right
    </div>

    (note, prefer to avoid the inline styling, but it demonstrates the point). This just makes our panel fill the whole space.

    Flush your site and presto, one Intranet link that displays any page you like in a custom frame.

    I've tested it out and it works a treat.

    Some improvements you could make: have the URL to the iframe page as a property of the IntranetPanel class, or generalise it even further into an external page panel class. Probably fix up the styling so you don't have messy in-line stuff.

  • Matt Hardwick
    Avatar
    Community Member
    61 Posts

    Re: creating a new tab with LeftAndMain that is just a frame underneath Link to this post

    mmm, perhaps I am missing something;

    I needed to put    

    Object::addStaticVars('LeftAndMain', array(
             'extra_menu_items' => array(
                'Intranet' => 'intranet/'
             )
          ));

    as I am running 2.2.2 and the add new items method isn't available, everything appears to work fine... BUT, when the page is rendered, it renders the div (id="right") as 0px high... I changed this in firebug to 83% and it looked perfect, I edited the SS file, and refreshed the page and it's still saying 0px high.

    I have refreshed properly. What's gone wrong

  • Blackdog
    Avatar
    Community Member
    156 Posts

    Re: creating a new tab with LeftAndMain that is just a frame underneath Link to this post

    hey matt,

    did you end up getting this working for SS 2.2.2?

    if so would you mind sharing your code?

    thanks.

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