This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

The HTML block is often used to paste third party scripts and forms into a concrete5 page. Sometimes they break concrete5 when you next try to edit.

The cleanest solution may be to put such third party forms and scripts into an iframe (there are a few iframe blocks in the marketplace). An iframe is like a separate window to the web, so cannot interfere with whatever contains it.

However, often the whole reason for including the third party code is that you want it to do something with your page. You just wish it didn't try and do it in edit mode!

So here is how to create a new template for an html block that can't interfere with edit mode.

Below is the code for the regular view of an html block from yoursite.com/concrete/blocks/html/view.php.

 <?php  defined('C5_EXECUTE') or die("Access Denied."); ?>
 <div id="HTMLBlock<?php echo intval($bID)?>" class="HTMLBlock">
 <?php echo $content; ?>
 </div>

You need to copy that to yoursite.com/blocks/html/templates/yourtemplatename.php and then edit the file to:

<?php  defined('C5_EXECUTE') or die("Access Denied."); ?>
<div id="HTMLBlock<?php echo intval($bID)?>" class="HTMLBlock">
<?php 
$c=Page::getCurrentPage();
if ($c->isEditMode()){
  echo "<p>HTML Block content not shown in edit mode</p>";
} else {
  echo $content; 
}
?>
</div>

You could get fancier with the edit mode message, many blocks that do this put it into a shaded box using some core CSS classes, but the above is pretty much a minimum.

Then turn off all the concrete5 caches and clear them.

Then you add an html block and just put some test content into it (not the form or script) like:

<p>Hello</p>

Save the block. Then in "Custom Templates" select your custom template. Save the page, then go in and out of edit mode a few times and to and from the page to test the above works and shows Hello or the edit mode message correctly.

Once happy with the template and it is thoroughly tested, edit the page, edit the block and paste in the code for your form or script (ie. Only paste the third party code into a block that already has the edit mode template, or you will get stuck!!!)

If it all goes wrong, you can go to the sitemap via the dashboard and revert the page version.

Test it again and go in and out of edit mode a few times.

Once you are happy, you may re-enable whatever caches you use. But remember to always switch off and clear the caches before you edit that page, or you will end up with the view code showing on the edit mode page and breaking everything!

If you are working a lot with JavaScript or jQuery in html blocks, have a look at my jQuickie block.

Read more How-tos by JohntheFish

Loading Conversation