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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

How To Implement Page Sections


Go to End


9 Posts   3788 Views

Avatar
Leesy

Community Member, 6 Posts

4 February 2009 at 3:31am

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

Avatar
SalvaStripe

Community Member, 89 Posts

4 February 2009 at 3:47am

hello Lessy and welcome!

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

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

Avatar
Leesy

Community Member, 6 Posts

4 February 2009 at 3:51am

Edited: 04/02/2009 3:58am

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.

Avatar
SalvaStripe

Community Member, 89 Posts

4 February 2009 at 3:58am

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!

Avatar
SalvaStripe

Community Member, 89 Posts

4 February 2009 at 4:00am

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

Avatar
Leesy

Community Member, 6 Posts

4 February 2009 at 4:06am

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.

Avatar
SalvaStripe

Community Member, 89 Posts

4 February 2009 at 4:19am

Edited: 04/02/2009 4:25am

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

Avatar
Leesy

Community Member, 6 Posts

4 February 2009 at 5:27am

Edited: 04/02/2009 5:28am

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!

Go to Top