Witam, mam klase do templatów:
<?php
class Template {
var $strTemplateDir = './layouty/';
var $strBeginTag = '{';
var $strEndTag = '}';
var $arrValues = array();
function Teplate( $template_dir )
{
$this->strTemplateDir .= $template_dir;
}
function assign( $strVar, $strValue ) {
$this->arrVars[] = $this->strBeginTag . $strVar . $this->strEndTag;
$this->arrValues[] = $strValue;
}
function display( $strFile ) {
$strFile = $strFile.'.tpl';
$resFile = fopen( $this->strTemplateDir . '/' . $strFile, 'r' ); $strBuff = fread( $resFile, filesize( $this->strTemplateDir . '/' . $strFile ) ); $strTest = str_replace( $this->arrVars, $this->arrValues, $strBuff ); }
}
?>
uzywam tego w ten sposob:
<?php
$tpl = new template;
$tpl->Teplate( $wybrany );
$tpl->assign( 'cos', $jakaszmienna);
$tpl->assign( 'cos2', '<b>jakis kod html');
$tpl->display( 'index' );
?>
Wszystko dziala ladnie pieknie, ale widzialem kiedys w skrypcie phpbb ze tak jak wyzej mam "assign" bylo w tablicy... chcialbym to samo osiagnac tylko niewiem jak
Dokladnie chodzi mi o taki efekt:
<?php
$tpl = new template;
$tpl->Teplate( $wybrany );
$tpl->assign(
'cos' = $jakaszmienna,
'cos2' = '<b>jakis kod html',
// i tak dalej, po prostu wygodniej :) pomoze ktos ? 
);
$tpl->display( 'index' );
?>