Home > Article > Backend Development > PHP.MVC template tag system (3)_PHP tutorial
PHP.MVC标签语法
在基本的介绍之后,我们现在就可以来看看模板标签系统的语法.
在看具体的标签之前,我们应该定义什么作为我们的标签.为了写一个标签,我们使用<@ ... @>标签结点.左标签(<@)和右标签(@>)是默认的标签.如果必要的话,这些标签我们能够在phpmvc-config.xml中重新定义.
模板标签系统现在支持以下3种标签:包含指令,声明和表达式.我们现在来看看这些指令.
包含指令
包含指令能让我们将内容分隔为许多模块,比如:页眉,页脚或者内容.包含的页面可以是HTML,或者其他标签模板页.据个例子,下面的包含指令能用来包含一个页眉:
<@ include 'pageHeader.ssp' @>
一个包含指令在模板上下文种的例子:
<@ include 'pageHeader.ssp' @> |
声明
声明允许我们在模板种声明一个页面级别的变量,或者甚至其他包含页面.一个声明看起来像以下代码:
<@ salesAreaID = "Central District" @>
我们能够在模板文件中使用声明:
<@ saleMonth = data.getValueBean('SALE_MONTH') @>
<@ saleTitle = data.getValueBean('SALE_TITLE') @>
<@ dealHeading = data.getValueBean('DEAL_HEADING') @>
<@ salesAreaID = "Central District" @>
表达式
The expression tag allows us to execute expressions in the template page. The result of the expression will be included in the template page. The following expression will be used to display a simple string (salesAreaID) and can also retrieve the framework configuration Class attributes:
<@ =salesAreaID @>
<@ =viewConfig.contactInfo @>
In order to use these expressions, we have to declare before:
<@ salesAreaID = "Central District" @>
Or the properties of the ViewResourcesConfig object (viewConfig) are declared in the view-resources node:
contactInfo = "flash.jack@jackshost.com"
...
When using an object in an expression, we can write an object - Methods (object-method) are declared in standard PHP notation or dot-style notation:
The PhpMVC_Tags Object-Method Notation
PHP Style sales = data->getSales
Dot Style sales = data.getSales
With Method Params staff = data.getValueBean("STAFF")
Retrieve Data Array products = data->getValueBean("PRODUCTS_ARRAY")
In the next unit we will see how to use the template tag system to convert these Combined together to build the page.