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.

Archive /

Our old forums are still available as a read-only archive.

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

Different types of content on a single page


Go to End


9 Posts   5500 Views

Avatar
Bert

Community Member, 19 Posts

2 July 2008 at 9:25am

Edited: 02/07/2008 9:29am

I have a website which features different types of content on the same page. In the wireframe below you can see what I mean.

The home page has a title ("Welcome") and some introductory text beneath the title. I used a StaffHolder for this (which inherits the Page title and content field). For the news (which is only shown on the home page) I used StaffPages, which are children of the StaffHolder and also inherit the Page title and content. For the news items, I also added a date field to the StaffPages. The news is only shown on the homepage.

On the right of the page there is a JavaScript photo gallery. Each image can have a description, and you can go back and forth in the gallery without a page reload.

Beneath the photo gallery there are two banners. A banner is a just a div with a title, an image and a link. Multiple banners can be added, but this can also be limited (two banners maximum for example). These banners are shown on each page of the website.

Now, as I have told I was able to get the page title ("Welcome"), the introductory text, and the news items with an added date field right. What I can't seem to figure out is how to make the JavaScript photo gallery updatable from the CMS, and how to update the banners in the CMS. Since SilverStripe works from a page philosophy, not a "blocks" philosophy, i can't seem to figure out how to add extra content types to a page.

Avatar
Willr

Forum Moderator, 5523 Posts

2 July 2008 at 11:11am

Edited: 02/07/2008 7:52pm

Since SilverStripe works from a page philosophy, not a "blocks" philosophy

A page is just a 'object' if you want to control something that isnt a 'page' on the site you can make it a 'DataObject' which you can edit in the CMS via a complex table field, table field or even make a whole admin panel to edit them

How I would do the photogallery for that page? You would have a has_many link on Page.php so a Page has many Photo Banners

// mysite/code/Page.php

class Page extends SiteTree {
 ..
 static $has_many = array(
      'PhotoBanners' => 'PhotoBanner'
 );
}

then you would need to create a PhotoBanner.php file which extends dataobject. Im going to say for this a Banner has a title, a description and a image.

<?php
// mysite/code/PhotoBanner.php

class PhotoBanner extends DataObject {
     static $db = array(
        'Title' => 'Varchar',
        'Description' => 'Text'
     );
    static $has_one = array(
      'Image' => 'Image'
);
}

?>

Then you would add a HasManyComplexTableField to your CMS Fields in Page to edit the relationship

See
http://doc.silverstripe.com/doku.php?id=tutorial:5-dataobject-relationship-management
http://doc.silverstripe.com/doku.php?id=complextablefield

Avatar
Bert

Community Member, 19 Posts

2 July 2008 at 7:16pm

Edited: 02/07/2008 7:16pm

Thanks willr, I'll give that a try.

Avatar
Willr

Forum Moderator, 5523 Posts

2 July 2008 at 7:51pm

Edited: 02/07/2008 7:51pm

Note that the image in the dataobject should be in a has_one rather then the db.

Avatar
Bert

Community Member, 19 Posts

2 July 2008 at 8:30pm

One quick question: Will this also show up separatly in the sitetree (while of course not displaying the banners in the navigation)? Since these banners are shown on each page, it would make more sense to have a sitetree structure like this:

- Home
--- Newsitem 1
--- Newsitem 2
--- Newsitem 3
- About Us
- Our products
--- Product 1
--- Product 2
- Contact
- Banners
--- Banner 1
--- Banner 2

Avatar
Willr

Forum Moderator, 5523 Posts

2 July 2008 at 8:38pm

Edited: 02/07/2008 8:39pm

No. The site tree shows/ allows objects that have "extended" sitetree - see Page.php - Page extends SiteTree and the rest of your pages eg ArticleHolders extends Page which in turn extends site tree. So this enables you to create them in the side bar, and be pages on the site.

A dataobject on the other had cannot be a page, or created in that site tree list. So it suits things like banners which you dont want as pages. Instead you use Banner as a dataobject and use something like a complex table field which can be added to a tab in your page this allows control over the object (setting title, description, image etc)

Avatar
Bert

Community Member, 19 Posts

2 July 2008 at 8:51pm

Sorry for the high number of (stupid) questions, but I'm quite new to SilverStripe, and this is the first website I'm developing in it.

Do I understand you correctly if I create "Banners" as a StaffHolder, which then shows up in the sitetree (and turn off the option of displaying it in the site navigation)? And each banner in turn is a StaffPage, for which I add an extra "Image" tab, and a link textfield. Would it be possible to disable the content field, since this won't be required for the banners? And is it also possible for using the same internal page selector that the link button uses in the editor?

Avatar
Willr

Forum Moderator, 5523 Posts

2 July 2008 at 9:27pm

You could do that way - Each Banner as a BannerPage with defined fields but do you want the banner to be a page on the site? Or just a Image - if you want just a image - use a dataobject else use a BannerPage page type with the fields for image etc

Would it be possible to disable the content field, since this won't be required for the banners

in your getcmsfields method on BannerPage.php (if you decide to make it a page) you can put

$fields->removeFieldFromTab("Root.Content.Main","Content");

Go to Top