Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Different types of content on a single page

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

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

Page: 1 2
Go to End
Author Topic: 4440 Views
  • Bert
    Avatar
    Community Member
    19 Posts

    Different types of content on a single page Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Different types of content on a single page Link to this post

    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

  • Bert
    Avatar
    Community Member
    19 Posts

    Re: Different types of content on a single page Link to this post

    Thanks willr, I'll give that a try.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Different types of content on a single page Link to this post

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

  • Bert
    Avatar
    Community Member
    19 Posts

    Re: Different types of content on a single page Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Different types of content on a single page Link to this post

    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)

  • Bert
    Avatar
    Community Member
    19 Posts

    Re: Different types of content on a single page Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Different types of content on a single page Link to this post

    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");

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