Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Extending BlogModule

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 869 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Extending BlogModule Link to this post

    Hello, I'm trying to extend BlogModule, but it doesn't work.
    What I've done thus far:

    BlogEntryDecorator:

    <?php
    class BlogEntryDecorator extends SiteTreeDecorator {
    function extraStatics() {
       return array(
        'static $db' => array(
          "Source" => "Text",
          "SourceURL" => "Text"
        ),
       
    'has_one' => array(
    'Photo' => 'Image'      
    )
    );
    }

    function updateCMSFields(& $fields){
        $fields->addFieldToTab("Root.Content.Main", new TextField("Source"));
        $fields->addFieldToTab("Root.Content.Main", new TextField("SourceURL));
    $fields->addFieldToTab("Root.Content.Image", new SimpleImageField('Photo','An image for this Blog Entry'));
    }
    }

    added DataObject::add_extension('BlogEntry', 'BlogEntryDecorator'); to _config.php

    BlogSummary.ss:

    <div class="blogSummary">
    ...
    ...
       <% if BlogEntryImage %>
          <% control BlogEntryImage %>$CroppedImage(79,89) <% end_control %>
       <% end_if %>
       $Photo
       $ParagraphSummary
       <a href="$SourceURL">$Source</a>
    ...
    ...
    </div>

    When creating new form I get SimpleImageField for entering photo and 2 fields to enter source and sourceurl.
    When going to /admin I see the image properly uploaded, but source and sourceurl fields are empty
    Nothing shows on site
    Please Help!

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Extending BlogModule Link to this post

    OK, so I solved most of my problems, Source and SourceURL are imported properly and are usable. Photo is also viewable, but only on the actual blog entry page. For some reason blog summary doesn't show Photo an Source in <p>Izvor: <a href="$SourceURL">$Source</a></p>.

    The problem was:

    <?php
    class BlogEntryDecorator extends SiteTreeDecorator {
    function extraStatics() {
    return array(
    'db' => array( <===== needs to be 'db' instead 'static $db'
    "Source" => "Text",
    "SourceURL" => "Text"
    ),

    'has_one' => array(
    'Photo' => 'Image'
    )
    );
    }

    function updateCMSFields(& $fields){
    $fields->addFieldToTab("Root.Content.Main", new TextField("Source"));
    $fields->addFieldToTab("Root.Content.Main", new TextField("SourceURL));
    $fields->addFieldToTab("Root.Content.Image", new SimpleImageField('Photo','An image for this Blog Entry'));
    }
    }

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Extending BlogModule Link to this post

    OK, I have solved all of the problems.
    For some reason there was a bug:
    The template NewsHolder.ss (NewsHolder.php extends BlogHolder and .ss templates are basically the same) was including the wrong BlogSummary.ss (the one in /blog/templates/includes instead the one in /templates/blackcandy_blog/templates/includes folder; after renaming it to BlogSummary1.ss and including that one it didn't include anything, then I created new file, named it BlogSummary2.ss, copy-pasted all from BlogSummary1.ss to new BlogSummary2.ss and included that one all of it worked - be4 I did it I checked the permissions BlogSummary1.ss had and all seemed fine, I just can't figure it out why it hasn't worked, but it is working now)

    Topic can be closed, ty!

    869 Views
Page: 1
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.