Kri*_*ris 1 php xml template-engine conceptual
因为我一直很晚才回答标记php的问题,我实际上知道答案,我想我会尝试自己提问.
我已经在php中对自定义模板引擎进行了如此多的完整重写,这么长时间以来,我以为我会征求意见.
简而言之,这是我迄今为止实施的最重要的部分:
IView
兼容的类实例(IView
定义Render()
方法)
sprintf('//%s:*[@runat="server"]', $namespaceprefix )
$tag.localName
并实例化一个并将其附加到原始模板.main()
处理程序,处理程序将呈现它.我的模板基于xml.一个简单的模板目前看起来像:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:red="http://www.theredhead.nl/serverside">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title will be filed by the View depending on the Controller</title>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Main/" />
</head>
<body>
<!-- the entire body may be reset by the view using it, using XPath and DOM functions -->
<!-- Usually the PageHeader and PageFooter would be put back after clearing the body -->
<div id="PageHeader">
<img src="/Image/Get/theredhead_dot_nl.png" alt="Site Logo" />
</div>
<h1>www.theredhead.nl :: Test Template</h1>
<p>
Lorum ipsum dolar sit amet. blah blah blah yackadee schmackadee.
</p>
<div id="PageFooter">
Built by
<br />
<red:UserProfileLink runat="server" Username="kris" />
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
目前,这个输出(包括破碎的缩进):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:red="http://www.theredhead.nl/serverside">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Welcome to my site</title>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Main/"/>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Custom/"/>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Profile/"/>
</head>
<body>
<!-- the entire body may be reset by the view using it, using XPath and DOM functions -->
<!-- Usually the PageHeader and PageFooter would be put back after clearing the body -->
<div id="PageHeader">
<img src="/Image/Get/theredhead_dot_nl.png" alt="Site Logo"/>
</div>
<h1>www.theredhead.nl :: ModelViewController</h1>
<p>
Lorum ipsum dolar sit amet. blah blah blah yackadee schmackadee.
</p>
<div id="PageFooter">
Built by
<br/>
<div><div xmlns:profile="http://www.theredhead.nl/profile" class="ProfileBadge" style="font-size : .8em;">
<a style="text-decoration : none; border: none;" href="/Profile/View/kris">
<img style="float : left;" src="http://www.gravatar.com/avatar/5beeab66d6fe021cbd4daa041330cc86?d=identicon&s=32&r=pg" alt="Gravatar"/>
 Kris
</a>
<br/>
<small>
 Rep: 1
</small>
</div></div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
所以最大的问题是:你对必备功能有任何意见吗?
PS如果有人对完整的源代码感兴趣,请发表评论,当我达到合理的开发人员可用性水平时,我将在我的网站上提供.
为什么不使用PHP作为模板系统.PHP 是模板系统.
只是<?php=$variable;?>
在HTML模板中转储有什么问题?您可以使用foreach循环等.只需确保在无法访问任何您不想要的变量的范围内运行它.
自从我的Java/Struts噩梦以来,我对这样过于复杂的模板系统有着深深的仇恨.在更改所需的一项内容之前,您必须深入了解命名空间,xpath,自定义命名空间和所有这些内容.
归档时间: |
|
查看次数: |
1799 次 |
最近记录: |