phpGrid tm Document

Template Method

set_template_layout()

Parameter(s): (String Template)

Example:

$dg -> set_template_layout ($template);

Description:
A powerful function generates datagrid from a preformatted template string, which contains the output interspersed with special tags that phpGrid engine replaces with assigned content when display.

There are two special phpGrid template tags, DataField and Admin.

DataField Template Tag:

    {DataField:field_name1}
    {DataField:field_name2}
    {DataField:field_name3}
    ...

• phpGrid Admin Template Tag:

    {Admin:View}
    {Admin:Edit}
    {Admin:Delete}


The template tags are case insensitive. It means {Admin:View} are the same as {admin:view}, {admin:View}, and {Admin:view}. However, no space is allowed between colon.

Nothing explains better with an example. The following is a simple example of using phpGrid template function:

include("include/cls_db.php");
include("include/cls_datagrid.php");
 
$template =
"<tr>
    <td><b>Full Name</b></td>
    <td>{DataField:fname} {DataField:lname}></td>
</tr>
<tr>
    <td><b>Age</b></td>
    <td>{DataField:age}></td>
</tr>
<tr>
    <td colspan=\"2\" align=\"right\">
        <a href=\"{Admin:View}\">View</a> |
        <a href=\"{admin:Edit}\">Edit</a> |
	<a href=\"{Admin:Delete}\">Remove</a>
    </td>
</tr>";
 
$dg = new C_DataGrid("localhost", "my_login", "my_password", "database_name", "mysql");
$dg -> set_gridpath("include/");
$dg -> set_sql("SELECT * FROM Employees");
$dg -> set_sql_table("Employees");
$dg -> set_sql_key("employeeId");
$dg -> set_template_layout($template);
$dg -> display();
 

Example Output:

Full Name John Smith
Age 34<
Full Name Joe Blow
Age 22
... ...

Table open tag and close tag are automatically inserted during the run-time. You can still apply other phpGrid functions to your grid, such as alternative row color function: set_alt_bgcolor(); mouse over highlight function: set_onmouseover(); table style: set_table_style(); page size method: set_page_size() etc.

For more examples of this function, please see examples page.