Idea of using xml for templates _ PHP

Source: Internet
Author: User
Some time ago, I have been concerned about the php template Technology and received the customer's requirements: the whole site can use the template technology to control multiple templates. this project requires a powerful background, it mainly involves multiple templates, and the difficulty lies in the template import and identification and generation. I carefully examined the core technology of php templates, and began to look up strings and then define replacement variables, replace the data with the data, and then some time ago, I have been concerned about the php template technology, and received the customer's requirements: the whole site uses the template technology to control multiple templates, this project requires a strong background, mainly multi-template. the difficulty lies in template import, identification, and generation. I carefully examined the core technology of php templates, simply start searching for strings, define replacement variables, replace them with data, and output them on the output page. I will not talk about the cache involved.

Let's take a look at the disadvantages of this generation method: If you want to display data in the "plain style", of course, I will not talk about CSS, and we cannot really separate the data from the representation, the css style sheet is used for display. the project we receive now requires not only the selection of css style sheets, but also the "multi-mode" of data display. for example, see:

In order to easily describe the period below, I would like to express each part as follows: A, B, C, D, E, F, and G can represent the data display area, from the designer's perspective, there are global (p control A-G), TOP (A), LEFT (B), RIGHT (C, D, E, F) and FOOTER (G ), of course, you can divide it into more details, so that the display can be controlled by p,But this is not a template technology, Please understand that A two‑dimensional table is not called A template, which is irrelevant to the template. The so-called template is only related to "data layout". in data A, we can also represent A navigation, if you like. this is written in the traditional template technology as follows:

...


{$ SITE_TOP $} // cjjer creation


...

Replace () is a variable in the symbols {$ and $}. this is just a navigation when data is simple, however, if we want a very complex data display, it will be difficult to control, because it is difficult to put a large amount of output data in a variable to ensure no errors.

In addition, the traditional template (in php) is like this. it is okay to get the template file, load, and display it. The problem is when the web project (not completely a website) when it is very complicated, it is easy to replace errors and monotonous templates. although css can be used to control some displays, it is difficult to control the layout of data. for example, I don't want the e-zone today, you modify the template and reload the file ...?

Is there any easier solution?Yes.

I have put forward the following idea:

The template page is an XML document. the template node loads existing modules and loads xml-like data to generate files.(Forgive me, I think it is very easy to say so) I will discuss this template technology in detail below.

First, let's take a look at what modules I'm talking about. everyone knows that

Ah,

Here, of course, this label is meaningful to the project, indicating that the global module node is controlled. if a node appears on the template page The loaded module data with the corresponding name format:




[% TITLE %]










& % Format % &



Here I define this template node as an html source for loading and controlling the global environment. let's look at the topdata tag:

{% TOP_MESS % }<%= show_top_meun () %>

If the node is loaded, the generated file replaces the topdata node with the preceding html document template.Module

The module can also be an xml document, reload the module, or the final data.

When the xml templates of these module nodes are loaded, they are recognized by the program, loaded into the html level-2 module, and then put forward our"Xml-like data"Data in the tag, replace the corresponding node with regular expressions, and generate a file. here," xml-like data "is the data in this way:

{% TITLE %} <% = cjjer_hometitle % >{%/TITLE %}
{% STYLE %} default {%/STYLE %}
{% Site_top %} <% = get_cache (0) % >{%/site_top %}
{% Format_two %}

<蔿l light()%>


{%/Format_two %}
{% Site_footer %} <蔿l cc_footer()%> {%/Site_footer %}

Here, you may immediately understand what I am talking about "xml-like data". This method of loading data is also an xml analysis node, and then replace the regular expression directly. of course, you can include the file (asp, php ).

Now, you must be clear about the concept)

Here is a simple example (format_index.xml ):


{% Site_top %}

{% Home_bigflash %}
{% Format_two %}

{% Site_footer %}

Module:

// Format, which is the top one, not listed

// Home_bigflash








// Format_two

(& Format_two &)

They all display some layout labels of the data layout. Why can't we create such labels ourselves? For example, I now "create" a tag like this

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.