daGrevis Posted December 4, 2010 Report Share Posted December 4, 2010 Veidoju template sistēmu. ^__^ Tagad ir tā, ka katram failam, kurš ir domāts kā fails, kuru redzēs lietotājs, ir template fails ar HTML paplašinājumu. Tajā ir tikai HTML un, pagaidām, iespēja pirms tam (PHP failā) saglabāt kaut ko un tad izvadīt + komentāri. Vēlos izveidot ko šādu... {include "header.html"} <p>Sveiks, {$username}!</p> {* Komentārs, kuru klients neredzēs. *} {include "footer.html"} Lielās problēmas sagādā {include "header.html"}. Tātad Esmu ticis tik tālu, ka šeit ir pattern's, kurš "noķer" visus {include "foo"}... $pattern = '/{include "(.*)"}/'; Tālāk netieku... =( Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted December 4, 2010 Report Share Posted December 4, 2010 Template valodas veidošana vien ir FAIL. Tam ir paredzēts PHP. Quote Link to comment Share on other sites More sharing options...
101111 Posted December 4, 2010 Report Share Posted December 4, 2010 Nav jēga izgudrot riteni, tādiem mērķiem ir paredzēts Smarty. Quote Link to comment Share on other sites More sharing options...
sandis_m Posted December 4, 2010 Report Share Posted December 4, 2010 Kāds Tev būs ieguvums taisot to template sistēmu? Quote Link to comment Share on other sites More sharing options...
mefisto Posted December 5, 2010 Report Share Posted December 5, 2010 101111, tas tavs ritenis ir kantains. Php jau ir templeitu valoda. Nah jātaisa ir vel viens layer'is pa virsu? $user = new User( $_SESSION['uid'] ); $page = new Template( '/path/to/template.whateve.r'); $page->assign( 'username' , $user->get_username() ); $page->assign( 'title' , 'Muahahahah !' ); echo $page->render(); un fails /path/to/template.whateve.r satur <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title><?php echo $title; ?></title> </head> <body> <h1>Hi, <?php echo $username; ?>, welcome to the hell</h1> </body> </html> Pati klase Template tāda kā šeit: http://php.lv/f/topic/17701-html-atdalits-no-php/page__view__findpost__p__138431 Quote Link to comment Share on other sites More sharing options...
codez Posted December 5, 2010 Report Share Posted December 5, 2010 Šeit ir viss vajadzīgais, lai realizēto to, ko tu vēlies - izveidot galveno templetiut, kurā būtu headeris, footers un izveidot katrai sadaļai savu templeitu. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted December 5, 2010 Author Report Share Posted December 5, 2010 Liels paldies azazul un codez! ^__^ Kamēr vakar vakarā nebija ko darīt, salaboju arī Savu versiju (ķipa {include "foo.html"}), kuru gan tomēr neizmantošu. =P class template { public $tags; public $output; public function __construct() {} public function set( $key, $data ) { $this->tags[ $key ] = $data; } public function get( $key ) { return $this->tags[ $key ]; } public function output( $template ) { $this->output = file_get_contents( "styles/default/templates/{$template}" ); $this->output = preg_replace_callback( '/{include "(.*)"}/', create_function( '$matches', 'return file_get_contents( "styles/default/templates/" . $matches[ 1 ] );' ), $this->output ); $this->output = preg_replace( '/{\*(.*?)\*}/', '', $this->output ); forEach( $this->tags as $tag => $data ) { $this->output = str_replace( '{$' . $tag . '}', $data, $this->output ); } return $this->output; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.