Parsing Overview
By default, FUEL disables PHP code from being saved in your module data (you must change the sanitize_input setting for the module). FUEL has implemented the Dwoo PHP 5 based templating system.
MY_Parser
FUEL overwrites the default CodeIgniter Parser library with the MY_Parser library to implement the expanded Dwoo templating syntax.
String Helper Functions
FUEL comes with the following string helper functions to help with parsing and converting from the Dwoo templating syntax:
- php_to_template_syntax - Convert PHP syntax to Dwoo templating syntax. Must use the PHP alternative syntax for if and foreach loops to be translated correctly.
- parse_template_syntax - Parses a strings Dwoo templating syntax.
Non-Namespaced Functions
The following are non-namespaced functions that can be used in your application and will be translated by the templating system.
- {site_url('/my/path/')}
- {assets_path('images/my_asset.jpg')} - Maps to the assets_path() function
- {img_path('my_img.jpg')} - Maps to the img_path() function.
- {js_path('my_js.js')} - Maps to the js_path() function. The .js extension is optional.
- {swf_path('my_swf.swf')} - Maps to the swf_path() function. The .swf extension is optional.
- {media_path('my_movie.mov')} - Maps to the media_path() function.
- {pdf_path('my_pdf.pdf')} - Maps to the pdf_path() function. The .pdf extension is optional.
- {safe_mailto('my@email.com', 'text')} - Maps to the safe_mailto() function.
- {redirect('my_redirect_page')} - Maps to the redirect() function.
- {show_404} - Maps to the show_404() function.
Namespaced Functions
The following are namespaced functions that can be used in your application and will be translated by the templating system.
- {uri_segment(1, true/false)} - Maps to the uri_segment(n) function.
- {fuel_var} - Maps to the fuel_var() function.
- {fuel_model(model, array(key="val"...)} - Maps to the fuel_modules() function.
- {fuel_block(array(key="val"...))} - Maps to the fuel_block() function.
- {fuel_nav(array(key="val"...))} - Maps to the fuel_nav() function.
- {fuel_edit(id, label, module, xOffset, yOffset)} - Maps to the fuel_edit() function.
Note that several of the functions require an associative array paramter with the key="val" syntax.
Blocks
Tag pairs allow you to loop through arrays of data. The syntax requires an opening {my_var} and closing {/my_var} tag. For example:
$my_data = array();
$my_data[] = array('name' => 'Darth Vader', 'weapon' => 'light saber');
$my_data[] = array('name' => 'Han Solo', 'weapon' => 'blaster');
...
{loop $my_data}
{$name} - {$weapon}
{loop}
You can also iterate over objects. For example, you may have a user model with some custom methods on it:
...
$my_data = $this->user_model->find_all();
{foreach $my_data user}
{$user->name} - {$user->weapon}
{/foreach}
The user part can actually be any value. You cannot insert outside variables inside a tag pair block.
Conditional Statements
FUEL also allows for php like conditional statements to be inserted into the view using {if ... }, {elseif ...} and {/if}. For example:
{$name='Darth Vader'}
{if $name == 'Darth Vader'}
I am your father.
{/if}
Creating your own tags
Dwoo provides several ways for it to extend it's templating syntax through plugins. The Dwoo folder to add your plugins is located at application/libraries/dwoo/plugins.