|
Back
Creating New Block Types in PostNuke
This note is in response to a query on the PN bulletin board: http://forums.postnuke.com/phpBB2/viewtopic.php?t=2804
The question asks whether block types are limited to just left, center and right. The answer is: no, other block types can be defined with a bit of hacking.
The theme is passed the first letter of the block type, so it gets 'c', 'l' or 'r' to represent the three block types at present. The theme can format each of these types in any way it wants within the themesidebox() function. Any new type you define would need to ensure the first letter is unique within this group. This means a block type of 'header' for 'footer' is allowed, but 'callout' is not as 'c' has already been used to represent 'center' block types. This letter is stored in the database against the block.
The theme can then call up the block of which-ever type it wants and place the content where it wants. So you can define a block type of 'header' and the theme can display the 'header' blocks at the top of the themed layout. You are not limited to placing just one block here - you can defined any number of blocks in this area and they will all be displayed in teh correct order.
As well as the theme.php to handle the block types, the other thing to change is the Blocks module, so that other block types can be entered by the user. There about three places where the block type drop-down lists are defined and you will need to add your new block types to those lists. The changes are all in Blocks/admin.php. I have included here an example that includes the block type 'footer'. It is based on the PN.721 SE Blocks module (view admin.php).
I have expanded a site myself to include 'footer' blocks and 'header' blocks, so I have l, c, r, t and h blocks and they can all be entered on the standard blocks admin screen. The theme does not handle these block types any differently from each other except for where it places those block types ('l' on the left, 'r' on the right, 'f' under the main content etc.). However, each block type is formatted differently as they are formatted using a simple template. The template file is named with the block type letter prefix, so I have templates default.php, l-block.php, r-block.php etc. This offers a lot of flexibility yet results in a theme.php file that is extremely lean.
I hope that is enough to get you started. A demo of this should be available soon. I'll post a link when it is complete.
Last updated:
Wednesday, 28-May-2008 16:14:17 BST
|