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.

Archive /

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

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

creating a new tab with LeftAndMain that is just a frame underneath


Reply


4 Posts   1812 Views

Avatar
Matt Hardwick

Community Member, 61 Posts

27 August 2008 at 5:19am

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.

Avatar
Hamish

Community Member, 712 Posts

27 August 2008 at 9:24am

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.

Avatar
Matt Hardwick

Community Member, 61 Posts

27 August 2008 at 6:03pm

Edited: 27/08/2008 6:37pm

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 :(

Avatar
Blackdog

Community Member, 156 Posts

8 October 2008 at 12:40am

hey matt,

did you end up getting this working for SS 2.2.2?

if so would you mind sharing your code?

thanks.