Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Two column content

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

Page: 1
Go to End
Author Topic: 2726 Views
  • redactuk
    Avatar
    Community Member
    115 Posts

    Two column content Link to this post

    I'm pretty new to Silverstripe. I've been playing around with the default templates and would like some advise on the best way to handle two column content i.e. multiple pages with main content and then varyiong content in a smaller right column or side bar. I can see how the default Sidebar strcuture works well for showing a menu system, but what about when you want to include additional content further down that might be unique to each page. Anyone offer any advise?

    Note: My current thinking is that where this additional content is fairly static you just define additional Page layouts that include the static content you want, or alternative you actually add a secondary Content area to the database, so that via Admin area you can both add main content and content for the sidebar area?

    Any recommendations appreciated

    Thanks

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Two column content Link to this post

    I would suggest you to add a dataobject and make a many-many relationship with the pages, then you can create one data object and view its content all around the website.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Two column content Link to this post

    I think that creating a relationship would is way more complex than is needed - the simplest thing to do would be to just create an additional field the $db static on your Page class, then add an extra field in your getCMSFields() method:

    class Page extends SiteTree {
       
       public static $db = array (
          'SidebarTitle' => 'Varchar(255)',
          'SidebarContent' => 'HTMLText'
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab('Root.Content.Sidebar', new TextField('SidebarTitle', 'Sidebar Item Title'));
          $fields->addFieldToTab('Root.Content.Sidebar', new HtmlEditorField('SidebarContent', null));
          
          return $fields;
       }
       
    }

    Then in your template (wherever your sidebar content is) you can just add something like:

    <!-- Existing Sidebar Stuff -->
    <% if SidebarContent %>
       <div id="SidebarContent" class="sidebarItem">
          <h3 class="sidebarTitle">$SidebarTitle</h3>
          $SidebarContent
       </div>
    <% end_if %>

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Two column content Link to this post

    yes I agree but though ajshort's method is easy, you will have to duplicate content, my point is not to duplicate content.

  • sleeper
    Avatar
    Community Member
    6 Posts

    Re: Two column content Link to this post

    Sorry for brnging up an old post, but i prefer to read and comment on existing thread rather than start new ones...

    What is a dataobject and how do i create one?

    If im undertanding Nivanka correctly, i can create a data object and assign it ti whatever pages i want?
    So if i make a change to a dataobject that change is applied to all the pages that use this dataobject - much like a global php include?

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