2013-02-21 46 views
2

在我的系統 樣品什麼語言用於動態文本(名稱)文本

<html> 
<title>{name title}</title> 
{css load} 
{script load} 
<body> 
<div> 
{headers} 
</div> 

我怎麼做一個用於動態文本什麼語言? php與JavaScript?

+0

嘗試Antlr - > http://code.google.com/p/antlrphpruntime/ – 2013-02-21 12:49:49

+0

看起來像把手。 http://handlebarsjs.com/ – ashley 2013-02-21 12:51:03

回答

1

這似乎是使用的templating engine。有許多PHP和Javascript都可用。我建議讓谷歌周圍,並決定哪一個最適合您的要求。

+0

非常感謝,我會學習! – 2013-02-21 13:03:44

0
<html> 
<title><?php echo $title; ?></title> 
<?php 
echo '<script src='.$src.'> </script> '; 
echo '<link href='.$src.' /> '; 

?> 
<body> 
<div> 
<?php echo $header; ?> 
</div> 
+0

這是最糟糕的解決方案!你永遠不應該在任何生產網站上以這種方式混合HTML和PHP – itsid 2013-02-21 13:03:52

0

這看起來有點像smarty(點網),但你可以很容易地自己創建一個非常基本的模板引擎。

首先創建一個模板

//........ 
<div align="right"> 
    $name 
</div> 
//........ and the like 

然後添加你需要

$name = "TuyoshiiBrasil"; 

,並在你的PHP結束變量...

//fetch template und output 
$template = addslashes(implode('', file("std.tpl"))); //where std.tpl is the template above 
eval ("\$output = \"$template\";"); 
echo stripslashes($output); 

它幾乎沒有強大作爲你可以在網上找到的模板引擎,當你認識到它也使用不同的語法時, 但它很容易實現,因爲您只需要三行代碼