Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » How To Implement Page Sections

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 1819 Views
  • Leesy
    Avatar
    Community Member
    6 Posts

    How To Implement Page Sections Link to this post

    Hi all,

    I'm new to SilverStripe and I was wondering if someone could give me a little guidance with something I need to achieve. On our new website, we have a sidebar that contains our site navigation. Then under this is just a lot of wasted whitespace. So the plan is to fill this area with little sections of content: customer testimonials, featured products etc. But I'm not too sure how I would define these sections.

    I could put them into the templates but then to alter any of the text etc. you would need SilverStripe & HTML knowledge to be able to find the files and change them correctly. I know I can add extra content areas to each page within my CMS but this way wouldn't I have to have the same customer testimonials again & again?

    So basically, I need some way of being able to author little blocks of HTML content that are then included into a larger page, preferrably randomly (so you don't always get the same testimonial). Anyone got any suggestions for me?

    Thanks,
    Lee

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: How To Implement Page Sections Link to this post

    hello Lessy and welcome!

    you can create ".ss" files in the templates/Includes folder like "MySidebarLeftIframe.ss"

    then, you have so add this code in your Page.ss (or an ss file in your layout folder), where the HTML code should be.

    <% include MySidebarLeftIframe %>

    you can write html code in the MySidebarLeftIframe.ss like iframe, embet objects or simple code. (dont insert <html>,<head><body>.. just write html code).

    greetz

  • Leesy
    Avatar
    Community Member
    6 Posts

    Re: How To Implement Page Sections Link to this post

    Hi SalvaStripe,

    Thanks for the info. The trouble with doing it completely this way is that my director won't be able to change these sections himself - it'll need to be someone confident with HTML. What I need is a half & half solution. I can happily add a section to my template that can contain this information but it's how I can make this information editable from the admin interface that confuses me.

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: How To Implement Page Sections Link to this post

    you can create some pages in you cms admin, maybe a "Stuff Holder" page. its pagetype can keep "Page", but you should set it to "dont show in menu + search".

    then create many stuff children inside it.

    later, you can use this nice code in your Page.ss so controll its content, children etc..

    <% control Page(stuff-holder) %> <!-- just the URL -->
    This is $Title !!!<br />
    Lets see my children...
    <% if Children %>
    <% control Children %>
    <a href="$Link" class="$LinkingMode">$Title</a><br />
    <% end_control %>
    <% end_if %>
    <% end_control %>
    HERE YOU CONTROLLED THIS ONE PAGE, CHECKED IF IT HAS CHILDREN, THEN YOU CONTROLLED ITS CHILDREN!!!

    HERE IS ANOTHER WAY, IF YOU DONT NEED $Content oder $Title OF THE HOLDER PAGE. IF YOU JUST NEED THE CHILDREN OF SUCH AN CERTAIN HOLDER, USE THIS:

    <% control ChildrenOf(stuff-holder) %> <!-- just the URL -->
    <a href="$Link" class="$LinkingMode">$Title</a><br />
    <% end_control %>

    YOU COULD TAKE if tags too, like <% if Title = Stuff Holder %> AND AROUND IT USUAL control menu(1),level(1) ... ... etc | but this i dont like that much!

    i hope you can use some code of this!

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: How To Implement Page Sections Link to this post

    hm i dont realy understand your Main problem.
    i will read your posts again, overthink it then i answer again!

  • Leesy
    Avatar
    Community Member
    6 Posts

    Re: How To Implement Page Sections Link to this post

    I think you're answer will get me on the right track so thanks I'll give it a shot and see how I go.

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: How To Implement Page Sections Link to this post

    you know how to use the $Layout / layout folder?
    there you can create many different page types. mostly layout is needed to have different styles for the content container area. the main Page.ss will be the same, just at $Layout there are the different page type included.

    but you can create a different main page type where you will have completely new html page just with an other page type.

    there you have to create a new page type, BUT IN THE PHP FILE WHAT YOU ARE CREATING dont write

    class MyNewMain extends Page {... ...

    class MyNewMain_Controller extends Page_Controller { ... ...

    YOU HAVE TO WRITE:

    class MyNewMain extends SiteTree {......

    class MyNewMain_Controller extends ContentController {... ...

    and the new ss file should be in templates, not in templates/layout. then you have a kompletly new site with other page typ, and not just a diffent part in your same html!

    ##### PS: ######
    i hope you can understand my english ;) i try my best

  • Leesy
    Avatar
    Community Member
    6 Posts

    Re: How To Implement Page Sections Link to this post

    You got me well on my way SalvaStripe - Thanks Here's what I did in the end for completeness.

    1. I created a top level page called "Customer Testimonials". This is set to not show in menus or search.

    2. Under here I created a number of child pages.

    3. In my Page.ss file I added the following:

    function RandomTestimonial() {
    return DataObject::get_one('SiteTree', 'ParentId = 159', false, 'RAND()');
    }

    4. And then finally in my template I added:

    <% if ChildrenOf(customer-testimonials) %>
    <div id="testimonials">
    <h3>Customer Testimonials</h3>
    <% control RandomTestimonial %>
    <h6>$Title</h6>
    <div class="test-descrip">
    $Content
    </div>
    <% end_control %>
    </div>
    <% end_if %>

    So now the title & content from a random page under Customer Testimonial is show on my page. Fantastic.

    Cheers again for the help SalvaStripe!

    1819 Views
Page: 1 2
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.