Modules can provide blocks that can be placed anywhere in your Gallery layout. Think of Lego bricks, you can build your own layout by arranging blocks any way you want.
For a list of all existing blocks, please refer to Blocks in Theme Reference.
To create a block called Example in the test module:
<?php $blocks = array( 'Example' => array( 'description' => $gallery->i18n('Example block'))); ?>
{if $user.isRegisteredUser} {g->text text="Hello %s" arg1=$user.userName} {else} {g->text text="Welcome! Login to see more photos!"} {/if}
The block parameters need to be specified in the blocks.inc file:
<?php $blocks = array( 'Example' => array( 'description' => $gallery->i18n('Example block'), 'vars' => array( 'someNumber' => array( 'description' => $gallery->i18n('A number between 1 and 5'), 'type' => 'choice', 'default' => '5', 'choices' => array( '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5)), 'textToShow' => array( 'description' => $gallery->i18n('The text to be shown'), 'type' => 'text', 'default' => ''), ))); ?>
{assign var=someNumber value=$someNumber|default:5} {if empty($item)} {assign var=item value=$theme.item} {/if} {capture assign="defaultMessage"}{g->text text="This is an example block"}{/capture} {assign var=textToShow value=$textToShow|default:$defaultMessage} <div class="{$class}"> <p>{$textToShow}</p> <p>{g->text text="You chose number %s!" arg1=$someNumber} {if $item.canContainChildren} {g->text text="This is an album!"} {/if} </div>
To create a preload for our Example block of the test module, create a Preloads.inc file at modules/test/Preloads.inc with the contents:
<?php class TestPreloads { function preload(&$template, $preload, $paramSet) { static $loaded; if (!empty($loaded[$preload])) { return null; } $loaded[$preload] = 1; switch($preload) { case 'Example': /* To include a CSS file... */ $template->style('modules/test/MyCssFile.css'); /* To include a JavaScript file... */ $template->javascript('modules/test/MyJavaScriptFile.js'); return null; case 'ExampleTwo': // Put here the preloads for another block of your module } return GalleryCoreApi::error(ERROR_BAD_PARAMETER); } } ?>
Note:
{assign var=someNumber value=$someNumber|default:5} {if empty($item)} {assign var=item value=$theme.item} {/if} {capture assign="defaultMessage"}{g->text text="This is an example block"}{/capture} {assign var=textToShow value=$textToShow|default:$defaultMessage} {* Load some data *} {g->callback type="test.LoadItemData" itemId=$item.id myLimit=$someNumber} {if !empty($block.test.LoadItemData)} <div class="{$class}"> <p>{$textToShow}</p> <ul> {foreach from=$block.test.LoadItemData.items item=photo} <li>{g->text text="Photo name:"}{$photo.title}, {g->text text="Owner: %s" arg1=$photo.owner}</li> {/foreach} </ul> </div> {/if}
Note: