MENU

Flexible HTML code block in your blogs WYSIWYG editor

  Previous article Next article  

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!





Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  1 Comment

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

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: 23-06-2018
  Comments: 1
  http://cms.ms/XUKM


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!