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.

Customising the CMS /

Editing Include .ss files from the CMS


Reply


4 Posts   1779 Views

Avatar
jdi

Community Member, 34 Posts

24 August 2009 at 11:12am

Hey Guys,

I'm pretty new to silverstripe. I've had a hunt through the forums for this question but didn't find it:

I have a sidebar (themes/themename/templates/Includes/SideBar.ss) and I'm wanting to add it into my CMS so that the end user of this website can edit it.

How do I create a relative .php file so that there will be an entry available in the CMS back end that will allow me to modify a value such as '$PartnerLinks' which will be called to the SideBar.ss template file?

Also, this is my first post so hooray :D

Cheers,
Jackson

Avatar
b0bro

Community Member, 38 Posts

24 August 2009 at 1:09pm

Edited: 24/08/2009 3:36pm

Hi Jackson,

Welcome to the Silverstripe forums. I myself am new and have only been using SS for 3 weeks at my new job. For your problem this is how I would tackle it. Maybe a SS veteran would have a better way i dont know.

In the Code folder create a new php file and call it LinksHolder.php

LinksHolder.php should have the following code:

class LinksHolder extends Page {
   
   //Path to icon for the cms if you want a custom one, otherwise comment it out
static $icon = "";
   
   static $db = array(

   );
   
   static $has_one = array(

   );
   
   static $has_many = array(
   );
   
   // This makes sure that only links can be children
   static $allowed_children = array(
      'LinkItem'
   );
   
   function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->removeFieldFromTab("Root.Content.Main","Content");   
      return $fields;
   }
}

Then create a new file called LinkItem.php in the code folder

Here is the code to include in linkitem.php:

class LinksItem extends Page {
   
//Self explanatory, Its parent can only be LinksHolder and it cant be a root item.
   static $default_parent = 'LinksHolder';
   static $can_be_root = false;
   static $db = array(
      "LinkTitle" => "Text",
"LinkURL" => "Varchar"
   );
   
   static $has_one = array(

);

   function getCMSFields() {
$fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Main", new TextField("LinkTitle", 'Link Title'),"Content");
$fields->addFieldToTab("Root.Content.Main", new TextField("LinkURL", 'URL Address'),"Content");
return $fields;
}
}

class LinksItem_Controller extends Page_Controller {

}

At this point I would run a dev/build/?flush=1

//To be continued, be right back

Avatar
b0bro

Community Member, 38 Posts

24 August 2009 at 3:33pm

Okay, back.

Im not testing this as i go so if you got any errors on <yoursite>/dev/build/?flush=1 paste them here, possible i would have made some syntax errors.

Next,

Log into your cms, <yoursite>/admin And the create a new Links Holder page. Then click on behavior and uncheck "show in menues" and "show in search" then Save and Publish

Then feel free to create some new Links Item Pages in there for testing. Make sure you save and publish.

Next we need to edit page.php in your code folder

Within your class Page extends Sitetree {} include this function:

function mylinks(){
       return DataObject::get("LinksItem");
    }

Save page.php

Now lets get to your (themes/themename/templates/Includes/SideBar.ss) file and include this:

<ul>
<% control mylinks %>
<li><a href="$LinkURL" class="yourLinkClass">$LinkTitle</a></li>
<% end_control %>
</ul>

Hopefully that works for you. Again im not sure if its the best way around it, like you im only new to SS. Good luck let me know how it goes.

Avatar
jdi

Community Member, 34 Posts

24 August 2009 at 3:42pm

great I'll try that out when I get a chance, thank you very much for you time :)