From thedatabase documentation.
mergeCodeVariables($content="", $rs="", $prefix="{",$suffix="}", $oddStyle="", $evenStyle="", $tag="div")
// parses any string data for template tags and populates from a resultset or single associative array
// $content = the string data to be parsed
// $rs = the resultset or associateve array which contains the data to check for possible insertion
// $prefix & $suffix = the tags start and end characters for search and replace purposes
// $oddStyle & $evenStyle = CSS info sent as style='inline styles' or class='className'
// $tag = the HTML tag to use as a container for each template object record
In simple terms, this means that if you have a single array of data (as you may get from getIntTableRows() or other queries- it can be a 'simple','array' or 'associative'=>'array'), and you want to add markup, you can create a chunk with the markup and it will be outputted once for each array in the data set.
Example:
$chunk="<h2>Topic:{topic}</h2><h3>Type:{make}</h3> <p>Detail:{detail}</p>"//any html with {insertion_points}
$arr=array('topic'=>'car', 'make'=>'ford', 'engine'=>'V8');//note this an associative array of a single row of data.
$output=$etomite->mergeCodeVariables($chunk, $arr, $prefix="{",$suffix="}", $oddStyle="", $evenStyle="", $tag="div");
return $output;will result in:
Quote
Topic: car
Type: ford
Detail: V8
Type: ford
Detail: V8
This can be extended by calling an external chunk by using...
$chunk=$etomite->getChunk('chunkName');
...by using a database API to retrieve the data;
...by adding $oddStyle="class=\"odd\"", and $evenStyle="class=\"even\"" to add class names against the fields to apply css to each odd and even row.
...by adding various tags to the wrapper (ie. <p></p>, <div></div>, <tr></tr>) etc (or no wrapper at all).
Top tip: you can use a variety of characters to check for data insertion, if you use
$prefix="<!--", $suffix="-->"
then if no data exists for that field, the tags are outputted which actually marks up as html as comments and they actually dissappear from the browser!
For multi-dimentional arrays, and less overhead, you can also use parseChunk().
This post has been edited by Cris D.: 20 February 2009 - 11:57 AM


Help

Back to top
MultiQuote








