rtgx

Tvorba výstupu pomocou HTML šablón

Príkazy

fileResource ($fName, $addParams='alt=""title=""')

Vracia obsah súboru $fName. Akje to obrázok, nevráti obsah súboru, ale tag IMG.

Parametre:
$fName, string - názov súboru, TypoScript resource data type
$addParams, string - ďalšie parametre (atribúty). Defaultne prázny alt a title.
Výstup:
string - ak je to súbor typu jpg, gif, jpeg, png vracia tag IMG s cestou k obrázku. Ak je to HTML alebo TXT vracia obsah súboru.

getSubpart ($content, $marker)

Vracia časť zo vstupného reťazca uzavretú v komentároch s rovnakým názom značky. Napríklad vstupný reťazec je "Hello World. How are you?" a $marker je "###sub1###", potom funkcia vráti časť medzi dvoma značkami ###sub1### - " World. How are ".

Parametre:
$content, string - vstupný reťazec, zvyčajne obsah HTML šablóny
$marker, string - názov značky, ktorý je v šablóne zapísaný takto: "###[$marker]###"
Výstup:
string - reťazec vybranej časti, ak bola nájdená vo vstupnom reťazci

substituteMarkerArrayCached (
$content,
$markContentArray=array(),
$subpartContentArray=array(),
$wrappedSubpartContentArray=array()
)

Multi substitučná funkcia s cache.

Parametre:
$content, string - vstupný reťazec, zvyčajne obsah HTML šablóny
$markContentArray, array - pole s naplnenýmy značkami, ktoré budú podľa kľúča (###[nazov_znacky]###) nahradené vo vstupnom reťazci
$subpartContentArray, array - podobne ako markContentArray ale položky obsahujú celé časti šablóny (subparts)
$wrappedSubpartContentArray, array - An array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating.
Výstup:
string - skompletizovaný parsovaný obsah

Príklad

Zdrojový kód HTML šablóny, obsahuje všetky základné prvky: subparts, wrappedSubparts, marks:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head><title>Example template...</title></head>
<body>

<br /><br /><br />
<h2>Section description...</h2>

<br /><br /><br />
<em>Subpart decsription...</em>

<!-- ###REGISTRATION_SELECT_TYPE### begin -->

<!-- ###TYPES### begin -->
<h2><!-- ###LINK### -->###TYPE_TITLE###<!-- ###LINK### --></h2>
<p>###DESCRIPTION###</p>
<!-- ###TYPES### end -->

<!-- ###REGISTRATION_SELECT_TYPE### end -->

</body></html>

Vytvorenie šablóny zo súboru (cesta k nemu je nastavená v TS file->template):

	$this->totalTemplate = $this->cObj->fileResource( $this->conf['file.']['template'] );

Volanie nasledujúcej funkcie parseTemplate (v poli subjects je pole záznamov, napr. z databázy):

	$out = $this->parseTemplate( 'REGISTRATION_SELECT_TYPE', $this->subjects );

Pole List obsahuje záznamy z DB, ktoré sa budú renderovať do HTML šablóny:

	/**
* Parse the subpart of the template into content with the various variables
*
* @param string $subpart: Needed subpart of the template
* @param array $list: data array, data objects
* @return string $template: output template html
*/
function parseTemplate( $subpart, &$list = false ) {

// Arrays declaration
$template = array();
$marks = array();
$submarks = array();
$subparts = array();
$wrappedSubpart = array();

// Subpart rendering example
if( $subpart == 'REGISTRATION_SELECT_TYPE' ) {

$template['total'] = $this->local_cObj->getSubpart( $this->totalTemplate, '###'.$subpart.'###' );
$template['types'] = $this->local_cObj->getSubpart( $template['total'], '###TYPES###' );

// List of subject types
foreach( $list as $subject ) {

// Link to other command
$params = array(
'tx_rtgproject_pi1[cmd]' => 'COMMAND',
'tx_rtgproject_pi1[type]' => $subject['uid'],
);
$link = '<a href="'.str_replace( '&', '&', $this->pi_getPageLink( $this->id, '_top', $params ) ).'">';
$wrappedSubpart["###LINK###"] = array( $link, '</a>' );

$submarks['###TYPE_TITLE###'] = $subject['title'];
$submarks['###DESCRIPTION###'] = $subject['description'];
$typesRow .= $this->cObj->substituteMarkerArrayCached( $template['types'], $submarks, array(), $wrappedSubpart );
}

// Complete all subparts
$subparts['###TYPES###'] = $typesRow;
$template = $this->cObj->substituteMarkerArrayCached( $template['total'], $marks, $subparts, $subparts );
return $template;
}

return ''; // Empty output, no subpart
}