Php. MVC label Syntax
After a basic introduction, we can now look at the syntax of the template tag system.
Before we look at specific labels, we should define what we label as our tags. to write a label, we use the <@ ... @> label node. The left label (<@) and the right label (@>) are the default labels. If necessary, These tags we can redefine in phpmvc-config.xml.
The template label system now supports the following 3 types of tags: include directives, declarations, and expressions. Let's take a look at these instructions now.
Include directive
The include directive allows us to separate content into modules, such as headers, footers, or content. Included pages can be HTML, or other label template pages. For example, the following include instructions can be used to include a header:
<@ include ' PAGEHEADER.SSP ' @>
An example that contains instructions in the context of a template:
...
<body>
<center>
<table class= ' pagelayouttable ' >
<tr>
<TD class= ' PageHeader ' >
<@ include ' PAGEHEADER.SSP ' @>
</td>
</tr>
<!--PAGE CONTENTS-->
...
<!--PAGE FOOTER-->
...
</table>
...
</center>
</body>
Here's an example of the PAGEHEADER.SSP header file content will be inserted into the homepage the page is sent to the user's browser. This header file contains an expression:
<!--Page Header-->
<span>
<@ =viewconfig.getapptitle @>
</span>
This expression will be compiled and will be output at run time as:
<!--Page Header-->
<span>
Flash Jacks ' Sleek Tab Site
</span>
Statement
The declaration allows us to declare a page-level variable in the template species, or even other included pages. A declaration looks like the following code:
<@ salesareaid = "District" @>
We can use the declaration in the template file:
<@ salemonth = Data.getvaluebean (' sale_month ') @>
<@ saletitle = Data.getvaluebean (' sale_title ') @>
<@ dealheading = Data.getvaluebean (' deal_heading ') @>
<@ salesareaid = "District" @>
<link rel= ' stylesheet ' type= ' text/css ' href= './style/pagestyles.css '/>
<title>
...
</title>
<body>
...
</body>
In this example, we declare some page variables. The first 3 variables have been assigned to the Actionobject in the action class we created: Data.getvaluebean (' Sale_month '). The 4th variable is assigned a string value: Salesareaid = "District".
The declared variable can now be used in the page:
<!--start_page_contents_include-->
...
<!--Content section heading-->
<center>
Clearance Deals
<table class= ' productstable ' >
...
</table>
</center>
<center>
Todays Specials
<table class= ' productstable ' >
...
</table>
</center>
...
<!--end_page_contents_include-->
These page variables will be output as follows:
<!--Content section heading-->
...
...
An expression
The expression label allows us to execute an expression in the template page. The result of the expression is included in the template page. The following expression will be used to display a simple string (Salesareaid) or to retrieve the properties of the framework Configuration class:
<@ =salesareaid @>
<@ =viewconfig.contactinfo @>
In order to use these expressions, we have to declare before:
<@ salesareaid = "District" @>
Or the properties of the Viewresourcesconfig object (viewconfig) are declared in the View-resources node:
<view-resources
AppTitle = "Flash jacks ' Sleek tab Site"
ContactInfo = "flash.jack@jackshost.com"
...
</view-resources>
When using an object in an expression, we are able to write an object-method (Object-method) declaration in a standard PHP notation or point-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'll see how to use the template tag system to combine these together to build a page.