DooPHP IRC channel


Template Options Supported by DooPHP

Share your tips, snippets and experiences about DooPHP, and discuss about best DooPHP practices.

Template Options Supported by DooPHP

Postby RichardM » Thu Dec 10, 2009 11:50 pm

Hi,

This thread is designed to provide a full listing of all the DooView supported template tags you can use inside of your template files located by default in /protected/view/...

Please DO NOT ask any questions relating to the template tags in here and ask them instead in a new post (in a more suitable area of the forums). This post is intended to be used ONLY as a reference guide when working on your own template files!

Now that bits over and done with please make use of the following posts to help you in designing your template files :)

I will be adding to this over the next few days so please bare with me while I complete it all. I plan to provide a form of 'quick reference' and then more detailed info on each tags usage.
Last edited by RichardM on Fri Dec 11, 2009 12:07 am, edited 1 time in total.
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Quick Reference

Postby RichardM » Thu Dec 10, 2009 11:56 pm

Output Variables
This lets you output the value of a variable (normally a string or number) within your template

Controller:
Code: Select all
$data['foo'] = 'bar';

Template:
Code: Select all
foo is {{foo}}


Loop over array
This lets you loop over an array of data within your template

Controller:
Code: Select all
$data['names'] = array('leng', 'milos', 'richard');

Template:
Code: Select all
<ul>
<!-- loop names -->
<li>{{names' value}}</li>
<!-- endloop -->
</ul>
Last edited by RichardM on Fri Dec 11, 2009 12:05 am, edited 4 times in total.
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Pass variables to templates and output them

Postby RichardM » Thu Dec 10, 2009 11:56 pm

Outputting Variables

If you have a variable you want to display within your template you must first assign the data to an array to be parsed into DooView's render function. You can do this as follows:

MyController.php
Code: Select all
class MyController extends DooController {
     public function Index() {
          $data = array(); // Array of data we can use within our templates
          $data['foo'] = 'bar'; // Assign the string 'bar' to the tag 'foo'
          $data['site_title'] = 'Demo Site';
          $this->render('index', $data); // Pass our array of data to be accessible within the template
     }
}


Now in your view file you can output the variables as follows.

index.html
Code: Select all
<html>
<head><title>{{site_title}}</title></head>
<body>
<p>Value of foo is : {{foo}}</p>
</body>
</html>
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK


Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 0 guests

cron