1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » adding image to blogs in silverstripe 3
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 998 Views |
-
adding image to blogs in silverstripe 3

22 October 2012 at 12:41am
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
-
Re: adding image to blogs in silverstripe 3

23 October 2012 at 4:17am
<?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');
?> -
Re: adding image to blogs in silverstripe 3

25 March 2013 at 3:32am Last edited: 25 March 2013 3:33am
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 %>
| 998 Views | ||
|
Page:
1
|
Go to Top |

