7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Show images in ArticleHolder
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 2637 Views |
-
Re: Show images in ArticleHolder

26 November 2009 at 9:33pm
No no.. this isn't in ArticlePage.ss its in ArticleHolder.ss. The function works just fine in ArticlePage.ss
Maybe I didn't explain it clear enough..
Well here's how it is..I have Article 1, Article 2 and article 3, each with images and text.
In ArticleHolder.ss I'm trying to list out those 3 article's with the first image.
Image - Article 1
Image - Article 2
Image - Article 3
..and so on.. -
Re: Show images in ArticleHolder

2 December 2009 at 10:18pm
I still can't get this thing to work..
Can't find any help with this on the forum either.. -
Re: Show images in ArticleHolder

3 December 2009 at 3:44am
So the code you're using is
<% control Children %>
<% control ArticleBilder.First %>
$Attachment
<% end_control %>
<% end_control %> -
Re: Show images in ArticleHolder

3 December 2009 at 9:43pm
Here is all of the code for the images:
In ArticleHolder.ss
<% if GetArticleFirstImage %>
<% control GetArticleFirstImage %>
<% control Attachment.First %>
$Attachment
<% end_control %>
<% end_control %>
<% else %>
<a href="$Link"><img src="themes/tutorial/images/blank.jpg" /></a>
<% end_if %>In ArticleHolder.php
function GetArticleFirstImage($num=1){
$manager = DataObject::get_one("ArticlePage");
return ($manager) ? DataObject::get("ArticleBilde", "ArticlePageID = $this->ID", "SortOrder", "", $num) : false;
}In ArticlePage.php
$manager = new ImageDataObjectManager(
$this,
'ArticleBilder',
'ArticleBilde',
'Attachment',
array(
'Name' => 'Bildenavn',
'Description' => 'Beskrivelse'
),
'getCMSFields_forPopup_articlebilder'
);
$fields->addFieldToTab("Root.Content.Bilder",$manager); -
Re: Show images in ArticleHolder

4 December 2009 at 2:41am
Forgot that one..
Here:
In ArticleBilde.php
<?php
class ArticleBilde extends DataObject
{
static $db = array (
'Name' => 'Text',
'Description' => 'Text',
);
static $has_one = array (
'Attachment' => 'File',
'ArticlePage' => 'ArticlePage'
);
public function getCMSFields_forPopup_articlebilder()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Description'),
new FileIFrameField('Attachment')
);
}
}?>
-
Re: Show images in ArticleHolder

9 December 2009 at 1:40am
I have tried to get this to work with a fresh install of SS and just starting from scratch, but I still can't get the images to show up in the articleHolder.ss.
I've done this before, the only different is that I used DataObjectManager to manage a simple list of urls, and used this function to output it to the template:
function GetLinksInternal(){
$LinksPage = DataObject::get_one("LinksPage");
return ($LinksPage) ? DataObject::get("InternalLink", "LinksPageID = {$LinksPage->ID}") : false;
}And this works perfectly anywhere on the website, but when I do the same when I use imagedataobjectmanager or the filedataobjectmanager it only shows the content added in the imagedataobjectmanager or the filedataobjectmanager when you are on the right page.
-
Re: Show images in ArticleHolder

15 December 2009 at 11:49pm
I think I have found out why this isn't working.
Its the Get function, this part isnt right: ArticlePageID = $this->ID. When I just have ArticlePageID, all of the ArticleBilde are showing in a list. SS doesn't know what do get and doesn't output anything..I'm not that good at programming this kind of things, so how should I do this when I have an articleholder with serveral ArticlePages with images added to them, something like this:
Articleholder -> ArticlePage1 -> ArticleBilde1,ArticleBilde2,ArticleBilde2,
-> ArticlePage2 -> ArticleBilde1,ArticleBilde2,
-> ArticlePage3 -> ArticleBilde1,ArticleBilde2,Heres the function:
function GetArticleFirstImage(){
$manager = DataObject::get_one("ArticlePage");
return ($manager) ? DataObject::get("ArticleBilde", "ArticlePageID = $this->ID", "SortOrder") : false;
}
| 2637 Views | ||
| Go to Top | Next > |

