Ilja Posted September 15, 2008 Report Share Posted September 15, 2008 Sheit,izdariju mazu skriptinu...bet man vinsh ir palidzigs :) negribu kaut kadu Smarty vai t.c. izmantot... es esmu slinks-tapec loti maz un vienkarshi :D bet kaut ko vel uzrakstishu... PS ka varu-ta rakstu...kadi kommentari? ceru kaut kadam noderes,varbut citi ari palidzes kaut ko vel uzrakstit xD class Template{ var $template; var $fp; var $tags; var $datas; function Load($filename="./templates/index.html"){ $this->fp=fopen($filename,"r"); if ( !$this->fp ) echo "Cannot open Template:".$filename; $this->template=fread($this->fp,filesize($filename)); } function AddTag($tag,$data){ $this->tags[]=$tag; $this->datas[]=$data; } function Process(){ $this->template=str_replace($this->tags,$this->datas,$this->template); } function Render(){ return $this->template; } } Link to comment Share on other sites More sharing options...
v3rb0 Posted September 15, 2008 Report Share Posted September 15, 2008 php4 jau 2008-08-08 nomira. Link to comment Share on other sites More sharing options...
andrisp Posted September 15, 2008 Report Share Posted September 15, 2008 (edited) v3rb0, hm, pričom php4 ? Ah, tu laikam par var sintaksi.. Edited September 15, 2008 by andrisp Link to comment Share on other sites More sharing options...
Roze Posted September 15, 2008 Report Share Posted September 15, 2008 php4 jau 2008-08-08 nomira. Nu ganjauka vēl ilgi figurēs.. Kas attiecās uz templeitiem.. a nu kamdēļ vispār vaig fopen() / str_replace() utt??? PHP pats jau par sevi ir template.. index.php <? $data = getSomeData(); include('template.php'); ?> un template.php: <div><?=$data?></div> Jo visjautrāk paliek, tad kad templates un to veidotāji sāk mēģināt redefinēt kaut kādus ciklus / loopus u.c. php funkcionalitāti :) Link to comment Share on other sites More sharing options...
codez Posted September 15, 2008 Report Share Posted September 15, 2008 (edited) Lūk vienkārša funkcija templeta satura returnošanai: function load($XYZ__file,$XYZ__data){ extract($XYZ__data); ob_start(); require $XYZ__file; $XYZ__output = ob_get_contents(); ob_end_clean(); return $XYZ__output; } Izmantojam: echo load('templeits.tpl',array('a'=>5,'b'=>'cool','c'=>array(1,7,2,8))); templeits.tpl: <div> <div><?php echo $a; ?></div> <div><?php echo $b; ?></div> <?php foreach ($c as $v){?> <div><?php echo $v; ?></div> <?php } ?> </div> returnošanas fīča ir vajdzīga piemēram tāpēc,ja gribam vairākus templeitus salādēt vienā: echo load('viss.tpl',array('menu'=>load('menu.tpl',$meudata), 'content'=>load('content.tpl',$contentdata), 'header'=>load('header.tpl',$headerdata))); Edited September 15, 2008 by codez Link to comment Share on other sites More sharing options...
Ilja Posted September 15, 2008 Author Report Share Posted September 15, 2008 Lūdzu netaisīt muļķīgas QUOTEs ar includu man nepatik,bet shitais el deres...bet vienalga mans ir universalak ) un kada jega pec ta "var" ? xD Link to comment Share on other sites More sharing options...
codez Posted September 15, 2008 Report Share Posted September 15, 2008 (edited) bet vienalga mans ir universalak Kā jau Roze aizrādīja, kā tu ar savu sistēmu taisies teimpleitā realizēt, piemēram, ciklu, kur jāizvada 20 vienādi elementi no masīva? Edited September 15, 2008 by codez Link to comment Share on other sites More sharing options...
rpr Posted September 16, 2008 Report Share Posted September 16, 2008 Lūdzu netaisīt muļķīgas QUOTEs lietotaajam rakstiit php kodu templeitos arii nav praatiigi. Link to comment Share on other sites More sharing options...
andrisp Posted September 16, 2008 Report Share Posted September 16, 2008 rpr, ko tu domā ar vārdu "lietotājs" ? Link to comment Share on other sites More sharing options...
Kavacky Posted September 16, 2008 Report Share Posted September 16, 2008 Ja "lietotājs" kaut ko sajās, rakstot PHP ciklu, viņš tikpat labi sajās arī rakstot SuperDuperTemplateEngineValoda ciklu. Link to comment Share on other sites More sharing options...
marrtins Posted September 16, 2008 Report Share Posted September 16, 2008 Jo visjautrāk paliek, tad kad templates un to veidotāji sāk mēģināt redefinēt kaut kādus ciklus / loopus u.c. php funkcionalitāti :) Laikam katram jāuzraksta sava PHP template engine, lai saprastu, ka ātrāk/ērtāk to tomēr darīt ar pliku PHP :D Link to comment Share on other sites More sharing options...
Recommended Posts