Jump to:

7940 Posts in 1543 Topics by 946 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: 3103 Views
  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

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

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

    I still can't get this thing to work..
    Can't find any help with this on the forum either..

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show images in ArticleHolder Link to this post

    So the code you're using is

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

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show images in ArticleHolder Link to this post

    And your ArticleBilde class?

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

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

    ?>

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

    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.

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Show images in ArticleHolder Link to this post

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

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