Flexible HTML code block in your blogs WYSIWYG editor

  Previous article Next article  

Flexible HTML code block in your blogs WYSIWYG editor

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.6
  Last updated: 15-06-2017
  Comments: 1

Sometimes you need to add HTML-code to a blog article, i.e. an iFrame or some code to include a third party (YouTube) movie. Using a WYSIWYG editor this isn't possible, you need to put the code in a global content block or generic template and copy the tag in the text-editor. Having a small website this works fine, but for large websites it is a different story. The down side is you get lots of GCB's associated with different articles, the admin doesn't get clearer of it...

I like to see all text and code for an article at one place.
The solution wasn't that hard, I created a custom content block for code in each article. The editor can call that block with one smarty tag *in* the WYSIWYG editor.

  How to use

Open the CGBlog module and add a new Field Definition.

  • Name: codeblock
  • Type: Text Area
  • WYSIWYG: off
  • Public: checked

Add one line to the top of your summary template, directly after the {foreach ...} line:

{foreach from=$items item='entry'}
  {if !empty($entry->fields.codeblock->value)}
    {$codeblock = "{eval var=$entry->fields.codeblock->value}"}
  {/if}
  ...

And to the top of your detail template:

{if $entry->codeblock ne ''}
  {$codeblock = "{eval var=$entry->codeblok}" scope=global}
{/if}

When you create a new article you will see a new content block at the bottom of the page.
Copy your custom HTML code in this block!
At the place where you want to have the code included in the article add in the WYSIWYG editor the tag:

{$codeblock}

That's all!

A2 Webhosting CMS Made Simple




A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  1 Comment

CMS Made Simple 2.2.3.1 - Tutorials, tips and tricks - CMSMS 2.2.3.1

Flexible HTML code block in your blogs WYSIWYG editor

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.6
  Last updated: 15-06-2017
  Comments: 1

A2 Webhosting CMS Made Simple