Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

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

adding image to blogs in silverstripe 3


Go to End


3 Posts   4119 Views

Avatar
nmshah

Community Member, 21 Posts

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

Avatar
nimda

Community Member, 1 Post

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

Avatar
SSK

Community Member, 4 Posts

25 March 2013 at 3:32am

Edited: 25/03/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 %>