Yapter::Tutorial

Basic Example

The Template:
<html>
<head>
    <title>{page_title}</title>
</head>
<body>
    <p>This could be anything you want in this paragraph.</p>
    <p>The date is: <b>{date}</b>.
</body>
</html>
		 
The Code:
<?php
    //--- Include the Yapter template library.
    require('/the/path/to/yapter.php');

    // Now, create a new template
    $tp = new Yapter('basic.tpl');
    $tp->set('page_title', 'Welcome to the Yapter basic example.');
    $tp->set('date', date('m-d-Y'));

    // Parse the template file and replace the variables
    $tp->parse();
    // Output the page to the screen
    $tp->spit();

    // Note that you usually always end with these 2 lines.
    // An exception would be if you use the getContents() method.  See the API Docs for more info.
?>
		 

Intermediate Example

The Template:
<html>
<head>
    <title><b>PolarLava::Projects::Yapter::Tutorial</b></title>
</head>
<body>
    <p>This is just a sample body paragraph.</p>
    <p>Let's put a table here:</p>

    <table>
    <tr>
        <th>{1st_hdr}<</th>
        <th>{2nd_hdr}<</th>
        <th>{3rd_hdr}</th>
    </tr>
    [BLOCK row]
    <tr>
        <td>{1st}</td>
        <td>{2nd}</td>
        <td>{3rd}</td>
    </tr>
    [END row]
    </table>
</body>
</html>
		 
The Code:
<?php
    //--- Include the Yapter template library.
    require('/the/path/to/yapter.php');

    // Now, create a new template
    $tp = new Yapter('intermediate.tpl');
    $tp->set('page_title', 'Welcome to the Yapter intermediate example.');

    // Set the table headers
    $tp->set('1st_hdr', 'First');
    $tp->set('2nd_hdr', 'Second');
    $tp->set('3rd_hdr', 'Third');

    // Set the table data
    $cell_data = array(
    			0 => array('Row1 Cell1', 'Row1 Cell2', 'Row1 Cell3'),
    			1 => array('Row2 Cell1', 'Row2 Cell2', 'Row2 Cell3'),
    			2 => array('Row3 Cell1', 'Row3 Cell2', 'Row3 Cell3')
    				  );
    foreach ($cell_data as $idx => $array) {
    	$tp->set('1st', $array[0]);
    	$tp->set('2nd', $array[1]);
    	$tp->set('3rd', $array[2]);
    	$tp->parse('row'); // Build the row
    }

    // Parse the template file and replace the variables
    $tp->parse();
    // Output the page to the screen
    $tp->spit();

    // Note that you usually always end with these 2 lines.
    // An exception would be if you use the getContents() method.  See the API Docs for more info.
?>
		 

Advanced Example

The Template:
<html>
<head>
    <title><b>{page_title}</b></title>
</head>
<body>
    <p>This is just a sample body paragraph.</p>
    <p>Let's put a table here:</p>

    [BLOCK table AS table1]
    <table>
    <tr>
        <th>{1st_hdr}<</th>
        <th>{2nd_hdr}<</th>
        <th>{3rd_hdr}</th>
    </tr>
    [BLOCK row]
    <tr>
        <td>{1st}</td>
        <td>{2nd}</td>
        <td>{3rd}</td>
    </tr>
    [END row]
    </table>
   [END table]
</body>
</html>
		 
The Code: