Blocks Development

Blocks development, although it does share many properties with modules as far as they're still programmed in PHP, doesn't actually display content in the same way. Nor do they have pages or use many functions.

Getting Started

With blocks, the start of the file shares some properties with modules. The following code demonstrates what an example block's file might look like:

<?php

/**********************/
/* Your credits go here     */
/**********************/

if(!eregi("block-blockname.php", $_SERVER['PHP_SELF'])){
     header("Location: index.php");
}

$content = "";


These 3 lines:

if(!eregi("block-blockname.php", $_SERVER['PHP_SELF'])){
     header("Location: index.php");
}


basically redirect anybody who tries to access that block file directly to the index.php of the site.

Adding Content to the Blocks

Unlike modules, you don't add content to blocks by using an echo command.

To add content to a block, you use the $content variable and add stuff to it. (which is why there's always a $content = ""; at the top of every block underneath the other stuff I mentioned in the Getting Started section).

To add content to a block, the code might look like this:

$content .= "Your Content goes here";


You must always make sure there's a .= not just a = between $content and the "

This is because it then forces whatever's in between the "s to be added to whatever's in the $content variable already, rather than overwriting it.

You might now be wandering to yourself "But how does the $content variable display anything on screen unless it's in an echo statement somewhere?". The answer to this is simple.

Unlike Modules, blocks' overall layout is controlled in the theme, not the block itself. When a block is loaded, the theme loads the content of the block using an echo command that calls the $content variable when it's supposed to be.

Anything that's within an echo line inside the block files actually gets displayed above the block. Funny feature that, but it's how it goes because of the nature of the theme controlling the block.

Languages in Blocks

Languages in blocks are not the same as languages in modules. There isnt a seperate directory to store language variables for blocks, so they all pull the language from the main language file ( /language/lang-english.php ), so any definitions you need to include need to go in that file.