Как вывести в цикле все подключения блоков smarty? Делаю как написано ниже, но чет нифига. Проще говоря, нужно избавиться от кучи записей типа
$smarty->assign('title',$arr_meta_tags['title']);
$smarty->assign('keywords',$arr_meta_tags['keywords']);
$smarty->assign('description',$arr_meta_tags['description']);
$smarty->assign('news',$arr_meta_tags['news']);
$smarty->assign('content',$arr_meta_tags['content']);
$news_tpl = $smarty->fetch("news.tpl");
$smarty->assign('blok_news',$news_tpl);
и вывести это все в цикле. Плюс к тому, решить проблему неизвестности всех тегов в шаблоне (title, keywords, description и т.д.), чтоб осуществлялся поиск их в шаблоне и производилась замена на нужные блоки
index.php
<?php
$dirname = str_replace('\\', '/', dirname(__FILE__));
define('ROOT_DIR', $dirname);
require_once ROOT_DIR.'/engine/classes/core.class.php';
require_once ROOT_DIR.'/engine/classes/db.class.php';
require_once ROOT_DIR.'/engine/libs/Smarty.class.php';
$db = new DBConnect;
$DBQuery = new DBQuery;
$smarty = new Smarty();
$smarty->template_dir='tpl/templates/';
$smarty->compile_dir='tpl/templates_c/';
$smarty->config_dir='tpl/configs/';
$smarty->cache_dir='tpl/cache/';
try{
$option = 'index';
if(isset($_GET['section'])){
$opt = $_GET['section'];
$path = ROOT_DIR.'/engine/classes/'.$opt.'.class.php';
if(file_exists($opt)){
require_once $path;
if(class_exists($opt)){
$option = $_GET['section'];
}
}
}
$full_path = ROOT_DIR.'/engine/classes/'.$option.'.class.php';
require_once $full_path;
$view = new $option();
$view->getTemplate();
}
catch(Exception $e){
echo $e->getMessage();
}
core.class.php
<?php
abstract class Core{
public $template = 'default';
function replace($tmp_content){
$smarty = new Smarty();
$replace_tags = preg_match_all("/{\\$(.*)}/", $tmp_content, $array_result);
for($i = 0; $i < count($array_result[0]); $i++){
$mb = mb_strtolower($array_result[1][$i]);
$path_include = ROOT_DIR.'/tpl/templates/'.$this->template.'/'.$array_result[1][$i].'.tpl';
if(file_exists($path_include)){
$text_file = $smarty->fetch($path_include);
$tmp_content = $smarty->assign('$mb', $text_file);
}
}
$smarty->display(ROOT_DIR."/tpl/templates/default/main.tpl");
}
function getTemplate(){
$template_url = ROOT_DIR.'/tpl/templates/'.$this->template.'/main.tpl';
if(file_exists($template_url)){
$tmp = file_get_contents($template_url);
$tmp = $this->replace($tmp);
}else{
throw new Exception("Шаблон не подключен!");
}
}
abstract function getContent();
abstract function getTitle();
}