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

Show images in ArticleHolder


Go to End


21 Posts   5094 Views

Avatar
frabraha

Community Member, 49 Posts

26 November 2009 at 2:05am

I have a small little problem.

I have made an ArticlePage that uses the imagedataobjectmanager for images. What I'm trying to do is to show the first image in the ArticleHolder, in the Children list of articles.

I've been trying different things but can't get the image to show up. First thing I tried was something like this:

function GetFirstImage($num=1){ 
$manager = DataObject::get_one("ArticlePage"); 
return ($manager) ? DataObject::get("ArticleBilde", "ArticlePageID = $this->ID", "SortOrder", "", $num) : false; 
}

Avatar
UncleCheese

Forum Moderator, 4102 Posts

26 November 2009 at 3:42am

Assuming the name of the relationship on your ArticlePage is "Images", all you need is:

<% control Images.First %>
$ImageProperty1 $ImageProperty2
<% end_control %>

Avatar
frabraha

Community Member, 49 Posts

26 November 2009 at 3:51am

Couldn't make it work...

Here's is my code for this

   $manager = new ImageDataObjectManager(
			$this,
			'ArticleBilder',
			'ArticleBilde',
			'Attachment',
			array(
				'Name' => 'Bildenavn',
				'Description' => 'Beskrivelse' 
			),
			'getCMSFields_forPopup_articlebilder'
	);

What should I use as the relationship? Attachment?

Not as good at programming as I should be.. but learning.. :P

Avatar
UncleCheese

Forum Moderator, 4102 Posts

26 November 2009 at 4:09am

You need to be more specific than "couldn't make it work".. It's hard to help you if you don't tell me what the result was.

try this:

<% control ArticleBilder.First %>
$Attachment
<% end_control %>

Avatar
frabraha

Community Member, 49 Posts

26 November 2009 at 4:45am

Sorry about that.. It didn't output anything.

Going to try that last one tomorrow.

tnx

Avatar
Martijn

Community Member, 271 Posts

26 November 2009 at 6:15am

Just to be shure : You DO run ?flush=all after you made changes to the template files?

Avatar
frabraha

Community Member, 49 Posts

26 November 2009 at 6:41am

Yes, of course.. :) I even tried the dev/build.. but no luck..

Avatar
UncleCheese

Forum Moderator, 4102 Posts

26 November 2009 at 7:53am

This is on the ArticlePage.ss template? There's no reason that shouldn't work. Are you able to get output in <% control ArticleBilder %>?

Go to Top