Flexible HTML code block in your blogs WYSIWYG editor
Previous article Next articleSometimes 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:
{if !empty($entry->fields.codeblock->value)}
{$codeblock = "{eval var=$entry->fields.codeblock->value}"}
{/if}
...
And to the top of your detail template:
{$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:
That's all!
Comment Form
ReviewManager
ReviewManager
1 Comment
Your guide inspired me to look into doing this OOTB with the News module. You can complete the same objective with the news module by capturing the field and assigning the capture as a variable, which could then sit anywhere in the summary or detail article blocks.
{capture assign='codeblock'}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
{if $field->name =='codeblock'}
{eval var=$field->displayvalue}
{/if}
{/foreach}
{/if}
{/capture}