09/10/2018, 23:07
Nhúng code php vào trong templates ...
Xin chào,
- Các bạn hướng dẫn mình cách đặt đoạn Script .php vào trong file templates .tpl
- Ví dụ : mình chạy file index.php có chứa lệnh gọi file main.tpl trong thư mục templates, bây giờ mình muốn chèn thêm đoạn script <?php echo "Xin chào tất cả các bạn !"; ?> vào trong file main.tpl thì phải làm thế nào ?
- Chú ý : mình đã chèn thử đoạn script <?php echo "Xin chào tất cả các bạn !"; ?> vào file main.tpl & cho chạy thử file index.php có chứa lệnh gọi file main.tpl rồi mà vẫn không hiển thị được đoạn code <?php echo "Xin chào tất cả các bạn !"; ?> này lên được ... & đồng thời mình cũng thử đổi file main.tpl thành file main.php & dùng index.php gọi lại file main.php mà cũng không thể hiển thị được đoạn code đó lên được.
** Vậy mong các bạn hiểu biết về PHP giúp đỡ & hướng dẫn mình nhé ! Xin cám ơn ...
- Các bạn hướng dẫn mình cách đặt đoạn Script .php vào trong file templates .tpl
- Ví dụ : mình chạy file index.php có chứa lệnh gọi file main.tpl trong thư mục templates, bây giờ mình muốn chèn thêm đoạn script <?php echo "Xin chào tất cả các bạn !"; ?> vào trong file main.tpl thì phải làm thế nào ?
- Chú ý : mình đã chèn thử đoạn script <?php echo "Xin chào tất cả các bạn !"; ?> vào file main.tpl & cho chạy thử file index.php có chứa lệnh gọi file main.tpl rồi mà vẫn không hiển thị được đoạn code <?php echo "Xin chào tất cả các bạn !"; ?> này lên được ... & đồng thời mình cũng thử đổi file main.tpl thành file main.php & dùng index.php gọi lại file main.php mà cũng không thể hiển thị được đoạn code đó lên được.
** Vậy mong các bạn hiểu biết về PHP giúp đỡ & hướng dẫn mình nhé ! Xin cám ơn ...
Bài liên quan
<?
define ('IN_SITE', true);
define ('PHP_EX', '.php');
define ('PHP_INDEX', 'index' . PHP_EX);
include 'constant' . PHP_EX;
include 'config' . PHP_EX;
define ('SYS_ENABLED', '1');
define ('ARTICLE_FOCUS', '1');
error_reporting (E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime (0);
include './includes/cache' . PHP_EX;
$Cache = new Cache ();
$Cache->mod_cache = $cfg_mod_cache;
$cache_name = '';
if (($Cache->get_config () AND !$Cache->check_update_schedule ('schedule')))
{
$cache_name = $Cache->get_page_id ();
if (empty ($cache_name))
{
$Cache->cache_onoff (0);
}
else
{
if ($str = $Cache->get_cache ($cache_name) != false)
{
$gmt = ($Cache->option['timezone'] ? ' (GMT' . $Cache->option['timezone'] . ')' : ' (GMT)');
$datetime = $Cache->translate_date (gmdate ($Cache->option['full_date_time_format'], time () + $Cache->option['timezone'] * 3600)) . $gmt;
$str = preg_replace ('#(<!-- TodayDateBegin -->)(.*?)(<!-- TodayDateEnd -->)#si', '<!-- TodayDateBegin -->' . $datetime . '<!-- TodayDateEnd -->', $str);
echo $str;
exit ();
}
}
}
include './includes/mysql' . PHP_EX;
include './includes/template' . PHP_EX;
include './includes/home_info' . PHP_EX;
$DB = new DBSql ();
$Info = new Info ();
$Template = new Template ('./templates/' . $Info->option['template']);
include './languages/' . $Info->option['language'] . '/lang' . PHP_EX;
include './languages/' . $Info->option['language'] . '/lang_home' . PHP_EX;
$Lang = new Lang_Home ();
$Lang->Lang_Global ();
$Template->set_vars (array ('SITENAME' => $Info->option['site_name'], 'SCRIPT_VERSION' => $Info->option['script_version'], 'TEMPLATE_PATH' => './templates/' . $Info->option['template']));
$Info->check_website_close ();
include './includes/functions' . PHP_EX;
include './includes/functions_home' . PHP_EX;
$Func = new Func_Home ();
$Info->get_common ();
include './modules/global' . PHP_EX;
include './modules/' . $Info->get_mod () . PHP_EX;
$Template->set_files (array ('header' => $Info->tpl_header . '.php', 'main' => $Info->tpl_main . '.php', 'footer' => $Info->tpl_footer . '.php'));
if ($Cache->turn_on)
{
$Info->option['general_date_day'] = $Lang->data['general_date_day'];
$Info->option['general_date_day_short'] = $Lang->data['general_date_day_short'];
$Info->option['general_date_month'] = $Lang->data['general_date_month'];
$Info->option['general_date_month_short'] = $Lang->data['general_date_month_short'];
$Cache->set_cache_content (serialize ($Info->option));
$Cache->set_cache ('option', 'php');
$Cache->reset_cache_content ();
$Cache->set_cache_content (serialize ($Func->get_update_schedule ()));
$Cache->set_cache ('schedule', 'php');
$DB->close ();
if (empty ($cache_name))
{
$Cache->option = $Info->option;
$cache_name = $Cache->get_page_id ();
if (empty ($cache_name))
{
$cache_name = 'idx';
}
}
$Cache->reset_cache_content ();
$Cache->set_cache_content ($Template->show ('header', 1));
$Cache->set_cache_content ($Template->show ('main', 1));
$Cache->set_cache_content ($Template->show ('footer', 1));
$Cache->set_cache ($cache_name);
echo $Cache->get_cache ($cache_name);
}
else
{
$DB->close ();
$Template->show ();
}
?>