Location: PHPKode > projects > Content*Builder > contentbuilder/lib/smarty/plugins/function.padcells.php
<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     padcells
 * Author:   Eduardo Morales <hide@address.com>
 * Purpose:  Pad Cells in a table with <td></td>
 *           useful for dynamic tables
 *
 * Params:   cols: Number of columns
 *           Total: Total number of items
 *           class: if present, adds "class=" into the <td> tag
 *           extra: Extra parameters for the <td> tag
 *           text: Text to display the <td> and </td> tags (default is &nbsp;)
 *
 * Examples: {padcells cols=$numColumns total=$smarty.section.sectionname.total}
 *           {padcells cols=$numColumns total=$smarty.section.sectionname.total class='chartgallery'}
 *           {padcells cols=$numColumns total=$smarty.section.sectionname.total extra='colspan="3"'}
 *
 * -------------------------------------------------------------
 *
 * Practical Example:
 *
 *           {assign var=numColumns value=4} {* Change number of columns here *}
 *           {section name=sectionname loop=$items}
 *               {if not ( $smarty.section.sectionname.index mod $smarty.section.sectionname.total )}
 *                     <tr>
 *               {/if}
 *                       <td>Content Here</td>
 *               {if $smarty.section.sectionname.last}
 *                     {padcells cols=$numColumns total=$smarty.section.sectionname.total}  {* Use function padcells for padding *}
 *                     </tr>
 *               {elseif not ( $smarty.section.sectionname.iteration mod $numColumns )}
 *                     </tr>
 *                     <tr>
 *               {/if}
 *           {/section}
 *
 */

function smarty_function_padcells($params, &$smarty)
{		

    extract($params);
	
    if (!isset($params['cols']))	{
        $smarty->trigger_error("padcells: missing 'coln' parameter");
        return;		
	}	
	
    if (!isset($params['total']))	{
        $smarty->trigger_error("padcells: missing 'total' parameter");
        return;		
	}
	
    if (!isset($params['class']))	{
        $class = '';	
	}
	else {
	    $class = ' class="' . $class . '" ';	
    }

    if (!isset($params['extra']))	{
        $extra = '';	
	}
	else {
	    $extra = ' ' . $extra . ' ';	
    }    		
	
    if (!isset($params['text']))	{
        $text = '&nbsp;';	
	}	

    $end = $cols - $total % $cols;

    /* Line below Modified Tue, 11 Mar 2003 10:45 */

    if($end==$total || $end==$cols) {

        return;
    }

    for ($i = 0; $i < $end; $i++) {
        echo '<td' . $class . $extra . '>' . $text . '</td> ';
    }
}

/* vim: set expandtab: */

?>

Return current item: Content*Builder