Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Show images in ArticleHolder

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3038 Views
  • frabraha
    Avatar
    Community Member
    49 Posts

    Show images in ArticleHolder Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show images in ArticleHolder Link to this post

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

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

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show images in ArticleHolder Link to this post

    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 %>

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

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

    Going to try that last one tomorrow.

    tnx

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Show images in ArticleHolder Link to this post

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

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show images in ArticleHolder Link to this post

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

    3038 Views
Page: 1 2 3
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.