Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Homepage teaser image

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1264 Views
  • Monty
    Avatar
    Community Member
    19 Posts

    Homepage teaser image Link to this post

    Hi, at the moment I am displaying teasers from the PortfolioPage.php on the Homepage.php. Each portfolio page has a group of 3 images uploaded using the DataObjectManager.

    At the moment I am displaying the Portfolio name, blurb and all 3 images on the homepage OK.

    PROBLEM: I only want to display the first image of the group of 3 images on the homepage. Your assistance is appreciated.

    Page.php

    class Page_Controller extends ContentController {
    ...
    public function RandomChildren($max = 1) {
    return DataObject::get("PortfolioPage", null, "RAND()", null, "0, $max");
    }
    ...
    }


    Homepage.ss

    ...
    <% control RandomChildren(2) %>
    <% control PortfolioImages %>
    $MyPortfolioImage.SetWidth(180)
    <% end_control %>
    <% end_control %>
    ...


    PortfolioImage.php

    class PortfolioImage extends DataObject {
    static $db = array (
    'PortfolioImageTitle' => 'Text'
    );

    static $has_one = array (
    'MyPortfolioImage' => 'Image',
    'BelongToEventPage' => 'PortfolioPage'
    );

    public function getCMSFields_forPopup() {
    return new FieldSet(
    new TextField('PortfolioImageTitle'),
    new FileIFrameField('MyPortfolioImage')
    );
    }
    }

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Homepage teaser image Link to this post

    Hi Dave, great to see you using SS!

    I'm assuming you are outputting other information, not just the images (otherwise you could just limit the result set to 1).

    To just display the first image, I would just use the built in template stuff, ie:
    in Homepage.ss

    <% control PortfolioImages %>
    <% if First %>$MyPortfolioImage.SetWidth(180) <% end_if %>
    <% end_control %>

    havn't tested that but should work....
    Cheers!

  • Monty
    Avatar
    Community Member
    19 Posts

    Re: Homepage teaser image Link to this post

    Hey Nick, thanks man, too easy. Works perfectly! Loving SS by the way.

    Thanks again Nick

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