Smarty 3有一個選項來設置(分配)一個變量,然後將文件包含(獲取)到一個新變量。
如何在沒有Smarty課程的情況下做到這一點? file_get_contents
不起作用,還有別的嗎?使用沒有Smarty的fetch()?
例如,這是Smarty的代碼:
<?php
$variable = 'Hello World';
$smarty->assign('variable', $variable);
$content = $smarty->fetch('content.tpl'); // content.tpl have "{$variable}" inside
echo '<script>document.write("' . $content . '")</script>'; // this will output <script>document.write("Hello World")</script>
?>
我想這樣做不Smarty的:
<?php
$variable = 'Hello World';
$content = file_get_contents('content.php'); // content.php have "echo $variable;" inside
echo '<script>document.write("' . $content . '")</script>';// this needs to output <script>document.write("Hello World")</script>, but it's outputing echo $variable;
?>
你想分配變量還是使用修飾符? –
僅分配變量 - 輸出文件將回顯它們。例如$ var ='hi'; $ output = open('output.php');回聲&輸出; //需要返回'hi' – user2881986
output.php中會有什麼?這將是聰明的模板或什麼? –