Ik maak op mijn website gebruik van Smarty om templates te parsen, dit werkt allemaal leuk en aardig. Ik gebruik file_get_contents() om pagina's te includen en deze aan een smarty variabelen te koppelen. Het probleem is dat smarty en PHP code niet wordt geparst op de included pagina, html wordt wel correct weergegeven. Een stukje van mijn code:
index.php
<?php
// put full path to Smarty.class.php
require('/usr/lib/php5/Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'smarty/templates';
$smarty->compile_dir = 'smarty/templates_c';
$smarty->cache_dir = 'smarty/cache';
$smarty->config_dir = 'smarty/configs';
$smarty->assign('emailmessage', '');
$pages = array('home','about','links', 'contact', 'portfolio', 'cv');
$names = array('home' => 'Home','about' => 'Over mij','links' => 'Links', 'contact' => 'Contact', 'portfolio' => 'Portfolio', 'cv' => 'Curriculum Vitae');
if(!isset($_GET['p']))
{
$smarty->assign('content', file_get_contents('home.php'));
$smarty->assign('breadcrumb', '<a href="index.php">Home</a>');
$smarty->assign('title', 'Jurgen-Meijer.nl - Welkom op de webpagina van Jurgen Meijer');
}
else
{
if(!in_array($_GET['p'], $pages))
{
$smarty->assign('content', file_get_contents('home.php'));
$smarty->assign('breadcrumb', '<a href="index.php">Home</a>');
$smarty->assign('title', 'Jurgen-Meijer.nl - Welkom op de webpagina van Jurgen Meijer');
}
else
{
$smarty->assign('content', file_get_contents($_GET['p'].'.php'));
$smarty->assign('breadcrumb', '<a href="index.php?p='.$_GET['p'].'">'.$names[$_GET['p']].'</a>');
$smarty->assign('title', 'Jurgen-Meijer.nl - '.$names[$_GET['p']]);
}
}
?>
Het doel is dus dat ik Smarty code wil gebruiken op de included pagina's maar deze worden gewoon letterlijk op het scherm weergegeven. Is het misschien een optie om de variablen te parsen voordat ik hem aan een smarty var koppel en hoe moet dit?
3.041 views