merhaba arkadaşlar;
şuanda basit sade bi template sınıfı üzerinde çalışıyorum
sınıfım
<?php
class template_engine {
public $html_content;
public function file_import($template_file)
{
if (file_exists($template_file)) { $this -> html_content = file_get_contents($template_file); } else { exit ("<h3>The Not Found Template File : ".$template_file."</h3>"); }
}
public function template_loop($loop_name,$template_loop = array())
{
if (is_array($template_loop))
{
if (preg_match_all("/<!-- BEGIN: POST -->(.*?)<!-- END: POST -->/si",$this -> html_content,$cikti))
{
foreach($template_loop as $replace => $value) { $this -> html_content = str_replace("{".$replace."}",$value,$cikti); }
print $this -> html_content;
}
}
}
}
?>
kullanım
$template = new template_engine;
$blog_post_read = mysql_query("SELECT * FROM bblog_post ORDER BY post_id ASC");
while ($post_read = mysql_fetch_assoc($blog_post_read))
{
$template -> file_import("template/test.html");
$template -> template_loop("POST",array(
'POST_ID' => $post_read["post_id"],
'POST_TITLE' => $post_read["post_title"]
));
}
html yapısı
<!-- BEGIN: POST -->
<h1>{POST_ID} - {POST_TITLE}</h1>
<!-- END: POST -->
yapmakta olduğum template sınıfı bu şekilde tıkandığım daha doğrusu takıldığım nokta döngüyü <!-- BEGIN: Tag --> <!-- END: Tag -->
begin etiketinin olduğu yerden başlamasını ve end etiketinin olduğu yerde bitmesini sağlamak istiyorum nasıl yapıcam konusunda takıldı bana bu konuda yardımcı olursanız cok sevinirim arkadaşlar.