Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Editing Include .ss files from the CMS

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

Page: 1
Go to End
Author Topic: 1729 Views
  • jdi
    Avatar
    Community Member
    34 Posts

    Editing Include .ss files from the CMS Link to this post

    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

    Cheers,
    Jackson

  • b0bro
    Avatar
    Community Member
    38 Posts

    Re: Editing Include .ss files from the CMS Link to this post

    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

  • b0bro
    Avatar
    Community Member
    38 Posts

    Re: Editing Include .ss files from the CMS Link to this post

    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.

  • jdi
    Avatar
    Community Member
    34 Posts

    Re: Editing Include .ss files from the CMS Link to this post

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

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