ImpressPages CMS blocks
Blocks are the content containers in theme files. They can be filled in with widgets or populated with content by a plugin.
How to define block in your theme
Just add this line in your theme's layout file (by default ip_theme/lt_pagan/main.php):
<?php echo $site->generateBlock('myCustomBlock'); ?>
You can change 'myCustomBlock' to whatever you like, but there can't be two blocks with the same name in one page.
By defining a block you tell the system that there widgets could be placed. Since that moment you can start dragging items in your new block. Everything is handled automatically. If you want to remove the block, just remove this line. Widgets will be removed automatically when the whole page will be deleted.
Populate block content from plugin
You can create a plugin that automatically searches for a particular block and populates it with required data.
Add system.php file to your plugin root directory and add following code:
<?php
//change namespace to your plugin namespace
namespace Modules\plugin_group\plugin_name;
/**
* Plugin system class. Used to initialize the plugin. It should be called 'System'.
*/
class System{
/**
* Plugin initialization function. It is executed automatically on each pageview.
* Plugin should be installed in Developer -> modules tab. See hello world plugin example
*/
function init(){
//class used to dispatch and bind events
global $dispatcher;
//bind function to site's "generateBlock" event
$dispatcher->bind('site.generateBlock', __NAMESPACE__ .'\System::generateBlockContent');
}
/**
* Method, fired each time, when new block of content is being generated.
*/
public static function generateBlockContent (\Ip\Event $event) {
//we want to populate the content only to blocks that are called 'myCustomBlock'
if ($event->getValue('blockName') == 'myCustomBlock') {
$content = '<p>My content</p>'; //content that will be populated to the block. Always use views to genreate HTML. We put inline HTML for simplicity of example
$event->setValue('content', $content ); //register content
$event->addProcessed(); //say the system, that the content has been populated.
}
}
}
Now everywhere in your website block <?php echo $site->generateBlock('myCustomBlock'); ?> will be populated with "My Content" paragraph.
Download Slideshow plugin to see it in action!
If none of the plugins populate particular block with the content that block will be used to drop widgets.
Write a comment
You must be logged in to comment.