Re: [SMARTY] best practice - combining script output

From: Date: Wed, 28 Aug 2002 02:56:11 +0000
Subject: Re: [SMARTY] best practice - combining script output
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5845@lists.php.net to get a copy of this message
Okay here goes... main array setup looks like this: /** * Smarty Template System * {@link http://smarty.php.net/ smarty.php.net} * {@link http://smarty.incutio.com/ Smarty Wiki site} */ require_once('Smarty.class.php'); /** * Box Alignment - centered across both columns */ define('EBUS_CONTENT_CENTER','CC'); /** * Box Alignment - content to the left, comment in the right */ define('EBUS_CONTENT_LEFT','CL'); /** * Box Alignment - content to the right, comment left */ define('EBUS_CONTENT_RIGHT','CR'); /** * Box Alignment - two columns, left box */ define('EBUS_SIDEBY_LEFT','SBL'); /** * Box Alignment - two columns, right box */ define('EBUS_SIDEBY_RIGHT','SBR'); /** * Box Alignment - two column, left box, to rows high */ define('EBUS_SIDEBY_LEFT_SPAN2','SBL2'); /** * Box Alignment - two column, right box, to rows high */ define('EBUS_SIDEBY_RIGHT_SPAN2','SBR2'); /** * Box Alignment - last box of a two row high sideby */ define('EBUS_SIDEBY_FINAL','SBF'); /** * seconds in two days * used for the box cache timeout value */ define('TWO_DAYS', 86400*2); $jpgcache = '/jpgcache/'; $dbc = 'prdgenl'; $conn = &ADONewConnection('oci8'); //$conn->debug=true; $conn->PConnect('',${$dbc}['uid'],${$dbc}['pwd'],${$dbc}['sid']); $dbc = 'prdcrm'; $concrm = &ADONewConnection('oci8'); //$concrm->debug=true; $concrm->PConnect('',${$dbc}['uid'],${$dbc}['pwd'],${$dbc}['sid']); $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $t = new Smarty; $t->autoload_filters = array( 'pre' => array('showinfoheader') , 'output' => array('trimwhitespace')); $nt = new Smarty; //for non-caching $nt->autoload_filters = array( 'pre' => array('showinfoheader') , 'output' => array('trimwhitespace')); //email note, you really only need one instance of smarty, I was just making extra sure (read sloppy programming) I did not set the caching parameters incorrectly // section index $idx box index $bidx $idx = 0; $bidx = -1; $parms = array ( 'INSTNC' => $gwa_appl_instnc ,'SECT' => $gwa_sect['ad'] ); $sql = amp_sql_format($ebus_sql['sel_text'], $parms); $rs = $conn->Execute($sql); // setup the AlcoaDirect section $section[$idx]['name'] = 'AlcoaDirect'; $section[$idx]['comment'] = $rs->fields['CNTNT']; $box[$idx][++$bidx] = genbox('ADDEPOT', EBUS_CONTENT_CENTER); $box[$idx][++$bidx] = genbox('ADDEPCAT', EBUS_SIDEBY_LEFT);//, 'Total Pounds Ordered by Product Family'); $box[$idx][++$bidx] = genbox('ADDEPCNT', EBUS_SIDEBY_RIGHT, 'Online Order Statistics'); $box[$idx][++$bidx] = genbox('ADUNQUPM', EBUS_SIDEBY_LEFT_SPAN2); $box[$idx][++$bidx] = genbox('ADDEPINQ', EBUS_SIDEBY_RIGHT, 'AlcoaDirect Depot Inquiries'); $box[$idx][++$bidx] = genbox('ADUSECNT', EBUS_SIDEBY_FINAL, 'AlcoaDirect Customer Statistics'); $box[$idx][++$bidx] = genbox('ADHBC', EBUS_CONTENT_CENTER, 'AlcoaDirect Customer Hits by Category'); // page break before the ADHBC box $box[$idx][$bidx]['pb'] = true; $box[$idx][++$bidx] = genbox('ADHITSTRTGY', EBUS_SIDEBY_LEFT, 'Hits by Strategy Center'); $box[$idx][++$bidx] = genbox('ADRPTCNT', EBUS_SIDEBY_RIGHT, 'AlcoaDirect Report Usage'); $box[$idx][++$bidx] = genbox('ADNEWF', EBUS_SIDEBY_LEFT, 'New Features', 'left'); $box[$idx][++$bidx] = genbox('ADPLAN', EBUS_SIDEBY_RIGHT, 'Planned Functionality', 'left'); $box[$idx][++$bidx] = genbox('ADCUSTFB', EBUS_CONTENT_CENTER, 'Customer Feedback', 'left'); //$box[$idx][++$bidx] = genbox('PH', EBUS_SIDEBY_RIGHT, 'Future Home Of...'); and the page is displayed with: $nt->assign(array( 'SECTION' => $section ,'BOX' => $box ,'SC_DT' => ' - '.strftime('%B %e, %Y', mktime(0,0,0,date('m'),1,date('y'))-1) )); $nt->display('ebus.tpl'); genbox function looks like this: /** * return img tag to display a chart * * @author Jason E. Sweat * @since 2002-04-08 * @param string $p_graph_type the identifier used to identify the graph * @return string the html source to retrieve the graph */ function genbox($p_box_type, $p_style=EBUS_CONTENT_CENTER, $p_title='', $p_calign='center') { // import globals foreach (array_keys($GLOBALS) as $key) { if(!isset(${$key})) global ${$key}; } $out['style'] = $p_style; $out['title'] = $p_title; $out['conalign'] = $p_calign; switch ($p_box_type) { case 'ADUNQUPM': $out['content'] = getchart('unique_upm'); $out['comment'] = getcomment('unique_upm'); break; case 'ADHITSTRTGY': $graph_type = 'hits_by_strtgy'; $parms['BOX_TYPE'] = $graph_type; $sql = amp_sql_format( $ebus_sql['ad_chart_comm'], $parms); $rs = $conn->Execute($sql); $t->caching = true; $t->cache_lifetime = TWO_DAYS; if (!$t->is_cached('ebus_counter2.tpl', $graph_type)) { gen_graph($graph_type); } $out['content'] = $t->fetch('ebus_counter2.tpl', $graph_type); $out['comment'] = getcomment($graph_type); break; //snip the rest of the cases... case 'PH': $out['content'] = 'This space intentionally left blank.<br>Except for these words, that is.'; $out['comment'] = 'Surely you can think of something to go here!'; break; default: $out['title'] = 'WARNING:'; $out['content'] = "Box type '$p_box_type' does not exist!"; $out['comment'] = "Perhaps you should contact Jason Sweat (ACT-242-2702) to find out what it up with this."; } return $out; } the config file contains: site_title = "eBusiness Scorecard" main_col_width = "760" half_col_width = "380" half_col_width_inside = "370" layout = " border="0" cellpadding="5" cellspacing="0"" layout0 = " border="0" cellpadding="0" cellspacing="0"" the css is: table { border-color: black } td { font: Arial; border-color: black } .titlecell { background-color: #6699FF; } .titlefont { font: 18pt Arial Bold; color: white; } .boxtitlefont { font: 12pt Arial Bold; color: white; } .boxfont { font: 10pt Arial; } .commentcell { background-color: #99CCFF; } .boxcommentfont { font: italic 10pt Arial; } .main_title { font: 18pt Arial Bold; color: blue; } .comment { font: italic 12pt Arial; } .ctrfont { font: 10pt Arial; } .fineprint { font: 8pt Arial; } .good { color: green } .bad { color: red } .oborder { border: border: 5 black solid 1; padding: 15; } .iborder { border: 5 black solid 1; padding: 3; } .pb { page-break-before: always } a sampe content template looks like: ebus_chart.tpl: <img src="{$IMGPATH}{$IMGSRC}" border="0"{if $IMGALT} alt="{$IMGALT}"{/if}> {if $IMGSRC2} <img src="{$IMGPATH}{$IMGSRC2}" border="0"{if $IMGALT2} alt="{$IMGALT2}"{/if}> {/if} the main layout template looks like: {config_load file="ebus.conf"} <html> <head> <title>{#site_title#}{$SC_DT}</title> <link rel="stylesheet" type="text/css" href="ebus.css" /> <style> {literal} @media screen { .viewhide { display: none; visibility:hidden } } @media print { .viewhide { display: block; visibility: visible } } {/literal} </style> </head> <body> <div align="center"> <p class="main_title">{#site_title#}</p> {section name="s" loop=$SECTION} <table border="2" cellpadding="2" cellspacing="0"> <tr> <td class="titlecell" colspan="2" width="{#main_col_width#}" align="center"> <span class="titlefont">{$SECTION[s].name}</span> </td> </tr> {section name="b" loop=$BOX[s]} {if $BOX[s][b].pb} </table> <div class="pb"><img src="/img/spacer.png" border="0"></div> <table border="2" cellpadding="2" cellspacing="0"> {/if} <div style="page-break-inside: avoid"> {if 'CL' == $BOX[s][b].style} <tr align="center"> {if $BOX[s][b].title} <td class="titlecell" width="50%"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> {/if} {if $BOX[s][b].comment} <td class="commentcell" rowspan="2"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> {/if} </tr> <tr align="center"> <td width="*"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if}> {$BOX[s][b].content|default:"&nbsp;"} </td> </tr> {elseif 'CR' == $BOX[s][b].style} {if $BOX[s][b].title} <tr align="center"> <td class="titlecell" colspan="2" width="100%"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> </tr> {/if} <tr align="center"> {if $BOX[s][b].comment} <td class="commentcell"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> {/if} <td width="*"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if}> {$BOX[s][b].content|default:"&nbsp;"} </td> </tr> {elseif 'SBL' == $BOX[s][b].style} <tr align="center" height="100%"> <td width="{#half_col_width#}" valign="bottom" height="100%"> <table {#layout0#} width="100%" height="100%"> <tr> <td valign="top" height="50%"> <table {#layout0#} width="100%"> {if $BOX[s][b].title} <tr align="center"> <td class="titlecell" width="100%"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> </tr> {/if} <tr align="center"> <td width="100%"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if}> <span class="boxfont">{$BOX[s][b].content|default:"&nbsp;"}</span> </td> </tr> </table> </td> </tr> {if $BOX[s][b].comment} <tr> <td valign="bottom" height="50%"> <table {#layout0#} width="100%"> <tr align="center"> <td class="commentcell" width="100%"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> </tr> </table> </td> </tr> {/if} </table> </td> {elseif 'SBL2' == $BOX[s][b].style} <tr align="center" height="100%"> <td width="{#half_col_width#}" valign="bottom" height="100%" rowspan="2"> <table {#layout0#} width="100%" height="100%"> <tr> <td valign="top" height="50%"> <table {#layout0#} width="100%"> {if $BOX[s][b].title} <tr align="center"> <td class="titlecell" width="100%"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> </tr> {/if} <tr align="center"> <td width="100%"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if}> <span class="boxfont">{$BOX[s][b].content|default:"&nbsp;"}</span> </td> </tr> </table> </td> </tr> {if $BOX[s][b].comment} <tr> <td valign="bottom" height="50%"> <table {#layout0#} width="100%"> <tr align="center"> <td class="commentcell" width="100%"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> </tr> </table> </td> </tr> {/if} </table> </td> {elseif 'SBR' == $BOX[s][b].style} <td width="{#half_col_width#}" valign="bottom" height="100%"> <table {#layout0#} width="100%" height="100%"> <tr> <td valign="top" height="50%"> <table {#layout0#} width="100%"> {if $BOX[s][b].title} <tr align="center"> <td class="titlecell" width="100%"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> </tr> {/if} <tr align="center"> <td width="100%"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if} height="100%"> <span class="boxfont">{$BOX[s][b].content|default:"&nbsp;"}</span> </td> </tr> </table> </td></tr> {if $BOX[s][b].comment} <tr><td valign="bottom" height="50%"> <table {#layout0#} width="100%"> <tr align="center"> <td class="commentcell" width="100%"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> </tr> </table> </td></tr> {/if} </table> </td> </tr> {elseif 'SBR2' == $BOX[s][b].style} <td width="{#half_col_width#}" valign="bottom" height="100%" rowspan="2"> <table {#layout0#} width="100%" height="100%"> <tr> <td valign="top" height="50%"> <table {#layout0#} width="100%"> {if $BOX[s][b].title} <tr align="center"> <td class="titlecell" width="100%"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> </tr> {/if} <tr align="center"> <td width="100%"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if} height="100%"> <span class="boxfont">{$BOX[s][b].content|default:"&nbsp;"}</span> </td> </tr> </table> </td></tr> {if $BOX[s][b].comment} <tr><td valign="bottom" height="50%"> <table {#layout0#} width="100%"> <tr align="center"> <td class="commentcell" width="100%"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> </tr> </table> </td></tr> {/if} </table> </td> </tr> {elseif 'SBF' == $BOX[s][b].style} <tr align="center" height="100%"> <td width="{#half_col_width#}" valign="bottom" height="100%"> <table {#layout0#} width="100%" height="100%"> <tr> <td valign="top" height="50%"> <table {#layout0#} width="100%"> {if $BOX[s][b].title} <tr align="center"> <td class="titlecell" width="100%"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> </tr> {/if} <tr align="center"> <td width="100%"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if} height="100%"> <span class="boxfont">{$BOX[s][b].content|default:"&nbsp;"}</span> </td> </tr> </table> </td></tr> {if $BOX[s][b].comment} <tr><td valign="bottom" height="50%"> <table {#layout0#} width="100%"> <tr align="center"> <td class="commentcell" width="100%"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> </tr> </table> </td></tr> {/if} </table> </td> </tr> {else} {if $BOX[s][b].title} <tr align="center"> <td class="titlecell" colspan="2" width="{#main_col_width#}"> <span class="boxtitlefont">{$BOX[s][b].title|default:"&nbsp;"}</span> </td> </tr> {/if} <tr align="center"> <td colspan="2" width="{#main_col_width#}"{if $BOX[s][b].conalign} align="{$BOX[s][b].conalign}"{/if}> <span class="boxfont">{$BOX[s][b].content|default:"&nbsp;"}</span> </td> </tr> {if $BOX[s][b].comment} <tr align="center"> <td class="commentcell" colspan="2" width="{#main_col_width#}"> <span class="boxcommentfont">{$BOX[s][b].comment|default:"&nbsp;"}</span> </td> </tr> {/if} {/if} </div> {/section} {if $SECTION[s].comment} <tr> <td class="commentcell" colspan="2" width="100%" align="center"> <span class="comment">{$SECTION[s].comment}</span> </td> </tr> {/if} </table> {if ($smarty.section.s.rownum != $smarty.section.s.total)} <p class="pb" /> {/if} {/section} </div> </body> </html> HTH Jason ----- Original Message ----- From: "Van Den Berghe" <tom.vandenberghe@abopc-bvicb.be> To: "'Jason Sweat'" <sweatjejm@mchsi.com>; "Greg Elisara" <greg@dreamlabs.co.nz>; <smarty-general@lists.php.net> Sent: Tuesday, August 27, 2002 9:54 AM Subject: RE: [SMARTY] best practice - combining script output > Jason, > > Could you give some more explanation about your "boxes" solution? > Maybe a small example? Would help a lot. > > Thx. > > Tom

« previous php.smarty.general (#5845) next »