7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Homepage teaser image
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1040 Views |
-
Homepage teaser image

27 June 2010 at 4:08pm Last edited: 27 June 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.phpclass 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')
);
}
} -
Re: Homepage teaser image

27 June 2010 at 5:49pm Last edited: 27 June 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! -
Re: Homepage teaser image

27 June 2010 at 6:19pm
Hey Nick, thanks man, too easy. Works perfectly! Loving SS by the way.
Thanks again Nick
| 1040 Views | ||
|
Page:
1
|
Go to Top |

