Вы определяете $page_output
после его повторения. В тот момент, когда вы вызываете echo $page_output
, он еще не существует.
Попытка:
$page_output = "You've chosen {$template_select[0]}.";
$template = str_replace("-","_","{$_GET['select']}");
if ($template == "cuatro"){
include("templates/cuatro.php");
echo $page_output;
} elseif ($template == "ohlittl"){
include(dirname(__FILE__) . "/templates/ohlittl.php");
echo $page_output;
} else {
echo "Sorry, template not found.";
}
Хотя я понятия не имею, как вы настраиваете $template_select
, и если вы знаете, оно всегда будет называть одно и то же имя шаблона?
Альтернативный подход, который, я считаю, позволяет достичь того, что вы хотите:
$templates = array('cuatro', 'ohlittl');
$selectedTemplate = strtolower(str_replace("-","_",$_GET['select']));
foreach ($templates as $template)
{
if ($template === $selectedTemplate) {
include(dirname(__FILE__) . "/templates/" . $template . ".php");
echo "You've chosen {$template}.";
}
}