Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » adding image to blogs in silverstripe 3

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1862 Views
  • nmshah
    Avatar
    Community Member
    21 Posts

    adding image to blogs in silverstripe 3 Link to this post

    I am trying to add an option to add images to blog posts. Have used the post here http://www.ssbits.com/tutorials/2011/adding-an-image-to-a-blog-post-using-decorators-and-the-silverstripe-blog-module/

    I have changed the code as per ss3 requirements yet I don't see upload image option when creating a new blog post.
    Created a file BlogEntryDecorator.php inside mysite/code like:

    <?php
    class BlogEntryDecorator extends SiteTreeDecorator {

       static $has_one = array(
          'BlogImage' => 'Image'
       );

       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Images", new UploadField('BlogImage'));
          return $fields;
       }
    }

    and then in mysite/_config.php added the following line:

    DataObject::add_extension('BlogEntry', 'BlogEntryDecorator');

    Kindly suggest as to how can I make this work

  • nimda
    Avatar
    Community Member
    1 Post

    Re: adding image to blogs in silverstripe 3 Link to this post

    <?php
    #-------------------------------------------------------------
    # Silverstripe v3.0.2 BlogEntry Upload Image
    # Create file: mysite/code/ext/BlogEntryDecorator.php
    #-------------------------------------------------------------
    class BlogEntryDecorator extends DataExtension {

       static $has_one = array(
          'BlogImage' => 'Image'
       );

       public function updateCMSFields(FieldList $fields) {
          parent::updateCMSFields($fields);
          $fields->addFieldToTab("Root.Main", $BlogImage = new UploadField('BlogImage'), 'Content');
          $BlogImage->getValidator()->setAllowedExtensions(File::$app_categories['image']);
       }

    }
    ?>

    <?php
    #-------------------------------------------------------------
    # Edit file: mysite/code/_config.php
    #-------------------------------------------------------------
    Object::add_extension('BlogEntry', 'BlogEntryDecorator');
    ?>

  • SSK
    Avatar
    Community Member
    4 Posts

    Re: adding image to blogs in silverstripe 3 Link to this post

    Greatly appreciated, this update to SS 3.0.x. The SSbits entry (see above) is no longer up to date and generates an error.

    Don't forget to adjust \blog\templates\Includes\BlogSummary.ss, for example:

       <% if BlogHolder.ShowFullEntry %>
          $Content
       <% else %>
             <% if BlogImage %>
       <div class="captionImage left" style="width: 200px;">
             <% with BlogImage %>$CroppedImage(200,133)<% end_with %>
             </div>
             <% end_if %>
          <% control Content %>$Summary.NoHTML<% end_control %>
          <a href="$Link" title="<% _t('VIEWFULL', 'View full post: ') %> '$Title'">Read more...</a></p>
       <% end_if %>

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