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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Homepage teaser image


Go to End


3 Posts   1752 Views

Avatar
Monty

Community Member, 19 Posts

27 June 2010 at 4:08pm

Edited: 27/06/2010 4:42pm

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')
        );
    }
}

Avatar
NickJacobs

Community Member, 148 Posts

27 June 2010 at 5:49pm

Edited: 27/06/2010 5:50pm

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!

Avatar
Monty

Community Member, 19 Posts

27 June 2010 at 6:19pm

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

Thanks again Nick :)