The #Chisimba dynamic canvas: the simple version proposal
Tweet
74 days ago
Following on from the refactoring I have been doing, I have made a proposal to simplify the Chisimba templates using what I call the dynamic canvas. This proposal is only partly dynamic, in that the blocks that are rendered on the template can be changed, but only by the module author. A full dynamic canvas would allow for editing the blocks displayed by any suitably authorised member of the site. This will come later. Meanwhile, the use of blocks with the dynamiccanvas module can greatly simplify Chisimba templates, with a typical template looking as below:
Basically, a template renders into the canvas, and there are two kinds of blocks, those that belong to the module, and those that belong to another module. The format is MODULE:BLOCK, or just BLOCK for blocks from the module which owns the template.
It makes use of the output buffering features of PHP, and sends the output to a parser that parses the template for the block codes.
chisimba canvas blocks dynamiccanvas
| Trackback URL No trackbacks were found for this post | Comments 0 |
Block-based dynamic canvas for #Chisimba
Tweet
70 days ago
Since I code for relaxation, for the past few days of my holiday I have been doing some work on Chisimba to improve the way in which it renders its look and feel, as well as the way in which it parses templates to render content. Everything I do is backward compatible.
Following on from the idea of dynamic canvases, I have made it possible for Chisimba to render an entire template based on functionality of Chisimba that we call blocks. There are two types of blocks in Chisimba, narrow blocks and wide blocks. Narrow blocks work on the side columns of 2 and 3 column layout, and wide blocks work on the middle area of 1, 2 and 3 column layout.
To use blocks to make a template, it may be necessary to use output buffering. To do this, add the following to the top of the template:
<?php
ob_start();
?>
Then add the following to the bottom of the template:
<?php
// Get the contents for the layout template
$pageContent = ob_get_contents();
ob_end_clean();
$this->setVar('pageContent', $pageContent);
?>
You then need a layout template in your module that contains:
<?php
$objBlocks = $this->getObject('blockfilter', 'dynamiccanvas');
$pageContent = $this->getVar('pageContent');
$pageContent = $objBlocks->parse($pageContent);
echo $pageContent;
?>
In your controller, for methods that will render the block-based dynamic canvas, you need to ensure that you enable the layout template using:
$this->setLayoutTemplate('demo_layout.php');
For this to work, you need a version 3.0+ skin, and you need to use the Chisimba Canvas layout, which is as follows:
<div id="Canvas_Content_Body_Region1"></div>
<div id="Canvas_Content_Body_Region3"></div>
<div id="Canvas_Content_Body_Region2"></div>
Note that Canvas_Content_Body_Region2 is the middle, but needs to be presented last in order for the columns to float and align correctly.
For 2-column layouts this would be:
<div id="Canvas_Content_Body_Region1"></div>
<div id="Canvas_Content_Body_Region2"></div>
Blocks are inserted using JSON syntax as follows:
{
"display" : "block",
"module" : "modulename",
"block" : "blockname",
"blocktype" : "blocktype",
"titleLength" : "titlelength",
"wrapStr" : 0|1,
"showToggle" : 0|1,
"hidden" : "value,
"showTitle" : 0|1,
"cssClass" : "cssClass",
"cssId " : "cssId"
}
Thus, adding the above block to the left column in such a template would consist of including it in the Canvas_Content_Body_Region1 div as follows:
<div id="Canvas_Content_Body_Region1">
{
"display" : "block",
"module" : "modulename",
"block" : "blockname",
"blocktype" : "blocktype",
"titleLength" : "titlelength",
"wrapStr" : 0|1,
"showToggle" : 0|1,
"hidden" : "value,
"showTitle" : 0|1,
"cssClass" : "cssClass",
"cssId " : "cssId"
}
</div>
Everything except display, module and block are optional. A template made up in this way might look like:
<?php
ob_start();
$objFix = $this->getObject('cssfixlength', 'htmlelements');
$objFix->fixThree();
?>
<div id="threecolumn">
<div id="Canvas_Content_Body_Region1">
</div>
<div id="Canvas_Content_Body_Region3">
| Type: table |
|---|
| This is an example of a block rendered using type table. It places the title in a normal header cell, and the block output in a table cell. |
</div>
<div id="Canvas_Content_Body_Region2">
{
"display" : "block",
"module" : "dynamiccanvas",
"block" : "nonexistentblock"
}
</div>
</div>
<?php
// Get the contents for the layout template
$pageContent = ob_get_contents();
ob_end_clean();
$this->setVar('pageContent', $pageContent);
?>
Note that the lines
$objFix = $this->getObject('cssfixlength', 'htmlelements');
$objFix->fixThree();
are there to equalize the columns. This need will shortly be removed.
For a working example of this, see the dynamiccanvas module.
chisimba canvas blocks dynamiccanvas
| Trackback URL No trackbacks were found for this post | Comments 0 |


