xml| templates
A while ago, has been more concerned about the PHP template technology I, received the requirements of customers: The whole station using template technology, you can control multiple templates, this project requires a strong background, mainly multiple templates, the difficulty in the template's import and recognition and generation, I carefully inspected the template core technology PHP, No more than the lookup string begins, then defines the substitution variable, replaces it with the data, and then outputs the output page, and I stop talking about the cache involved.
Let's take a look at the drawbacks of the way this is generated: if you want to "multi-style" display data, of course, I do not say CSS, can not really separate the data and presentation, no matter how to use CSS style sheet display, we now receive this project not only requires the optional CSS stylesheet, but also requires data to display the " Many ways ", for example, look at the following figure:
In order to be easy to describe the period, I said the various parts: a,b,c,d,e,f,g These 6 areas can represent the data display area, from the designer's point of view, there is a global (Div control a-g), Top (A), left (B), right (c,d,e,f) and footer (G), of course, you can be more detailed, so, you can use Div control, but this is not a template technology , please understand that the multi-style sheet is not called template, which is irrelevant to the template, the so-called template is only related to the "Data layout", in a data we can also represent a navigation, If you like. This is written in the traditional template technology:
...
<div id= "Top" >
{$SITE _top$}//cjjer production
</div>
...
Replace () is a variable in the {$ and $} symbol. When the data is simple, the analogy is just a navigation, and if we want a very complex display of data, it's very difficult to control, because it's hard to keep a large amount of output data in a variable without making mistakes.
In addition, the traditional template (in PHP) is this, get the template file, load, show, that's fine, the problem is when the Web project (not exactly the site) is very complex, it is easy to replace the error and template monotonous, although you can control some of the display, but it is difficult to control the layout of the data, for example, E-Zone I don't want it today, you change the template, reload the file ...?
Is there a more easy solution? there is.
I have put forward the view that:
template page is XML document, template node loads existing module, loading "Imitation XML data" generation file (Forgive me, so I think it's very easy) I'll talk about this template technology.
First look at what I said the module is what, we all know, HTML <div> AH,<table> are display data layout of some of the layout labels, why we can not make this label ourselves? For example: I now "create" one such label < Format> here, of course, this tag is meaningful to the project, representing the module nodes that control the global, if node <format> load in the template page is the module data with the corresponding name format:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "http://www.w3c.org/TR/1999/REC-html401-19991224/ Loose.dtd ">
<title>[%TITLE%]</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<meta http-equiv= "Content-language" content= "ZH-CN"/>
<meta name= "Author" content= "[%author%]"/>
<meta name= "Copyright" content= "[%copyright%]"/>
<meta name= "description" content= "[%description%]"/>
<meta name= "keywords" content= "[%keywords%]"/>
<link href= "Styles/[%styles%]/import.css" rel= "stylesheet" type= "Text/css"/>
<body>
<div id= "Format" >
&%format%&
</div>
</body>
Here I define this template node as the HTML source to load control global, and then look at the tag topdata:
<div id= "Topdata" >{%top_mess%}<%=show_top_meun ()%></div>
If this node is loaded, the resulting file will replace the Topdata node with the HTML document template, which is the module
The modules here can also be XML documents, reload modules, or end data.
When these XML templates with module nodes are loaded, is recognized by the program, the corresponding loading into the HTML level two module, and then put forward our " imitation XML data " tags in the data, is replacing the corresponding node, generate files, where the "imitation XML data" is this way of data:
{%title%}<%=cjjer_hometitle%>{%/title%}
{%style%}default{%/style%}
{%site_top%}<%=get_cache (0)%>{%/site_top%}
{%format_two%}<div id= "Footer_ul" ><%call Light ()%></div>
{%/format_two%}
{%site_footer%}<%call cc_footer ()%>{%/site_footer%}
Here, you might immediately understand what I mean by "imitating XML data," which is the XML parsing node, and then directly replacing it with a file (asp,php).
Well, now you must have the concept very clear, (not clear to look back at the words, or look at the example below)
Let me give you a simple example to illustrate (Format_index.xml):
<format>
<site_top>{%site_top%}</site_top>
<format_two>
{%format_two%}
</format_two>
<site_footer>{%site_footer%}</site_footer>
</format>
Module:
Format, which is the top one, does not enumerate
Home_bigflash
<div id= "Main_img" >
<object classid= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase= "http://download.macromedia.com/pub/ shockwave/cabs/flash/
swflash.cab#version=6,0,29,0 "width=" 100% ">
<param name= "movie" value= "http://www.163design.net/x/f/images/main.swf" >
<param name= "wmode" value= "Transparent" >
<param name= "Quality" value= "High" >
<embed src= "http://www.163design.net/x/f/images/main.swf" quality= "High" pluginspage= "http://" Www.macromedia.com/go/getflashplayer "type=" Application/x-shockwave-flash "width=" 100% "></embed>
</object>
</div>
Format_two
<div id= "Format_two" > (&format_two&) <script language= "JavaScript" type= "Text/javascript" src= "js/" Same_h2.js "></script> </div>
Site_footer
<div id= "Site_footer" > (&site_footer&) </div>
Templates and modules that should be loaded on this point (all can be reused.)
[1] [2] Next page