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.

Archive /

Our old forums are still available as a read-only archive.

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

Blog module doesn't use the standard HTML form?!


Go to End
Reply


10 Posts   5990 Views

Avatar
darkowl

Community Member, 12 Posts

30 November 2007 at 2:45pm

Edited: 30/11/2007 2:45pm

Hi,

I just noticed when using the blog module, that it doesn't support the standard HTML text entry (and TinyMCE editing capabilities) of a standard Silverstripe page. Instead, it opts for the insanity of having a BBcode parser?!

My main concern with this is that the TinyMCE controls remain active, and it's very misleading to go and try to insert an image, only to have the JavaScript controls fail in an error because it can't find any target textarea controls to use.

Given that this HTML editing ability seems to be a core part of the Silverstripe system, I would like to know why the blog ignores it and opts for a non-HTML BBcode solution instead? It seems almost counter-productive.

I tried to do a little bit of hacking about to change the textarea from the BBcode one to a standard Silverstripe HTML one, and it worked okay in the admin, but saving resulted in a catastrophic failure which broke the blog posts on the public side.

Is there any possibility that a future release of the blog module could scrap the BBcode and instead just use the HTML controls provided? It'd make life a lot more pleasant, I feel :)

Avatar
DaveP

Community Member, 48 Posts

30 November 2007 at 3:27pm

Hi Thanks for raising this - I was just about to enter a similar post

Also I'm wondering why there is an inconsistency when entering links.

If you right click on some highlighted text, and select Insert/Edit text you get a pop-up dialog to enter the details. If instead you click the hyperlink icon on the html toolbar, you get a Link section appear on the right to enter the details.

Plus there are differences - e.g. the pop-up one has a class selection.

regards, Dave Porter
DJ Software

Avatar
Anatol

126 Posts

30 November 2007 at 4:09pm

Edited: 30/11/2007 4:22pm

Hi,

I think the main reason for BBCode is to add/edit blog articles on the published site using the Blog Management Widget. I did not want to do without the comfort of the TinyMCE editor either; I found it quite straightforward to modify the blog module. You probably found out how to change the Textarea field in the CMS to a HTMLEditorField through getCMSFields() in BlogEntry.php:

$fields->addFieldToTab("Root.Content.Main", new HtmlEditorField("Content", "Content", 20));

The paragraph summary that displays a short summary of blog articles in the Blog Holder, however, simply cuts off the text of blog modules. This is OK with BBCode, but with html code it may break the layout of blog posts on a Blog Holder page. So the next thing I modified was to replace the ParagraphSummary() and ParsedContent() methods in BlogEntry.php with:

function ParagraphSummary(){
   return $this->Content;   
}

function ParsedContent() {
   return $this->Content;
}

There may be a more efficient way, but I wanted to make as little changes to the original code as possible so a future update of the blog module would be less painful.

Optional:
- - - - - - - - - - - - - - - - - - - - - - - -
To get the possibility to add a "read more/read the full post" link to the blog summary the easiest way I find is to add another field to the CMS, again in getCMSFields() in BlogEntry.php add this line below all other field definitions:

$fields->addFieldToTab("Root.Content.Main", new HtmlEditorField("ContentMore", "More", 10));

To add the field to the database add "ContentMore" => "Text" to the $db array in BlogEntry.php:

static $db = array(
   "Date" => "Datetime",
   "Author" => "Text",
   "Tags" => "Text",
   "ContentMore" => "Text",
);

I also added a new function that is useful for the template to the BlogEntry class:

function hasReadMore() {
   if ($this->ContentMore == '' || $this->ContentMore == '<p></p>') {
      return false;
   }
   return true;
}

You can then use this function in the BlogSummary.ss template, e.g.:

<% if hasReadMore %>
<a href="$Link" title="Read Full Post">Read the full post</a>
<% end_if %>

To display the additional content add the $ContentMore variable to the BlogEntry.ss template, e.g.:

<h3>$MenuTitle</h3>
$Content
$ContentMore

- - - - - - - - - - - - - - - - - - - - - - - -

To clean up the code you can delete or comment the BBCodeHelp fields and any BBCode related lines from both BlogEntry.php and BlogHolder.php and remove the Blog Management Widget ($managementwidget) in the requireDefaultRecords() method in BlogHolder.php

run /db/build/?flush=1 and the blog now hopefully uses the html editor and still provides the functionality of a blog summary. You loose the Blog Management Widget, but I can live with that.

Maybe I forgot a few minor adjustments, but it should be enough information to make it work.

Cheers!
Anatol

Avatar
perfectfool

Community Member, 3 Posts

15 March 2008 at 1:07am

Great summary, just one correction. The extra ContentMore field type in the $db array should be 'HTMLText', with no trailing comma:

static $db = array(
   "Date" => "Datetime",
   "Author" => "Text",
   "Tags" => "Text",
   "ContentMore" => "HTMLText"
);

Avatar
asfahaan

Community Member, 6 Posts

4 April 2008 at 7:09pm

Can someone post their edited and working files mentioned above? It would really help.

Cheers,
Asfahaan

Avatar
Willr

Forum Moderator, 5513 Posts

7 April 2008 at 3:16pm

If you don't want to use BBCode and want to revert to using TinyMCE you can add BlogEntry::allow_wysiwyg_editing();

Avatar
Anatol

126 Posts

9 May 2008 at 12:44pm

Hi willr,

thank you for that hint. This new option is great!

Please note that as I am writing this you need the latest daily build of the blog module ([url]http://dailybuilds.silverstripe.com/modules-tarballs/[/url]), not the version in the regular download section.

You may also need to make a little change in the template file, e.g. I am using the Olive Sunset template and had to change
$Content.Parse(BBCodeParser)
into
$ParsedContent
in the file BlogEntry.ss (in the olivesunset_blog section).

A similar change is necessary in the BlogSummary.ss file.

Avatar
fgalopo

Community Member, 1 Post

20 May 2008 at 12:23am

Hi,

I'm a fresh new user of SilverStripe (what a great cms!), everything's fine, only one issue with the blog module:

I'm using the latest build of the module (05/18/2008), with the "BlogEntry::allow_wysiwyg_editing('true');" option and the vista theme.
I can add the entry using the html editor, when I view the post on the summary it's displayed ok, but when I try to view the full post (using the "read the full post" button):
the post is displayed with the full html code (without interpreting it).

What (and where) do I need to change the code to make it work?

Thanks a lot for your help,
FG

Go to Top