'; ?> DomCore Demos, a WebAbility® Network Project
« Back to the index

\core\WATemplate elements example

Relax mode

##maintitle## Let's print some results.
In the normal mode, the recommended syntax of parameters, languages and fields, to identify them rapidly by nature in your templates:
__PARAM__ are simple parameters used to build the template,
##entry## are language entries (titles, helps, etc),
{field} are information fields, and generaly come from a database record.
This syntax is OPTIONAL, however HIGHLY RECOMMENDED.
Note the normal elements (added with ->addElement() ) are NOT metaelements, and you must not use { { and } } for them.

##title1##: {value1}
##title2##: {value2}
##title3##: {value3}

EOF; $temp = new \core\WATemplate($template); // the use of addElement, addElements or metaelements for SIMPLE ELEMENTS is exactly the same result, use the one that you prefer based on your needs // Only the way to pass through the parameters change. // all the elements are CUMULATIVE $temp->addElement('##maintitle##', ' elements'); $temp->addElement('##maintitle##', ' example'); // You can also insert elements in REVERSE mode, i.e. at the beginning of others added elements of same ID $temp->addElement('##maintitle##', 'Simple', true); // Some simple parameters in arrays $temp->addElement( array('__WIDTH__', '__HEIGHT__', '__COLOR__'), array('200px', '100px', '#800') ); // metaelements can be called ONLY ONCE $temp->metaElements( array( '##title1##' => 'City', '##title2##' => 'Engineer', '##title3##' => 'Advance', '{value1}' => 'Mexico', '{value2}' => 'Pedro Perez', '{value3}' => '80%', ), false, false ); print $temp->resolve(); // STRICT MODE print "

Strict mode

"; $template = <<##maintitle## Let's print some results.
In the strict mode, you may use any type of name syntax without worrying about the names conflict, since they are all included into { { and } }.

It is highly recommended to ALWAYS use the strict mode.
Note the normal elements (added with ->addElement() ) are NOT metaelements, and you must not use { { and } } for them.

{{title1}}: {{value1}}
{{title2}}: {{value2}}
{{title3}}: {{value3}}

EOF; $temp = new \core\WATemplate($template); // the use of addElement, addElements or metaelements for SIMPLE ELEMENTS is exactly the same result, use the one that you prefer based on your needs // Only the way to pass through the parameters change. // Simple elements are NOT meta elements, Do not use {{...}} since they are a metaelement // all the elements are CUMULATIVE $temp->addElement('##maintitle##', ' elements'); $temp->addElement('##maintitle##', ' example'); // You can also insert elements in REVERSE mode, i.e. at the beginning of others added elements of same ID $temp->addElement('##maintitle##', 'Simple', true); // Some simple parameters in arrays $temp->addElement( array('__WIDTH__', '__HEIGHT__', '__COLOR__'), array('300px', '150px', '#008') ); // you do not need to add {{ and }} to the elements and metaelements in strict mode. addElements() is a deprecated synonym of metaElements() // metaelements can be called ONLY ONCE $temp->metaElements( array( 'title1' => 'City', 'title2' => 'Engineer', 'title3' => 'Advance', 'value1' => 'Mexico', 'value2' => 'Pedro Perez', 'value3' => '80%', ), false, true ); print $temp->resolve(); ?>



« Back to the index