Table of Contents

Request for Comments: Improved short tags for templating

Rationale

Many template systems use PHP as its underlying language, so that the templates could be parsed and run by the efficient PHP engine, edited by PHP tools, benefit from PHP performance solutions, etc. PHP template can be written in two ways, with full tags:

This is a home page for <i><?php echo $user; ?></i>. 
Last visited at <?php echo $lastvisit; ?>. 

or short tags:

This is a home page for <i><?= $user ?></i>. 
Last visited at <?= $lastvisit ?>. 

The second form looks much nicer and cleaner, and can be easily understood and edited by non-PHP people like graphical designers, copy editors, etc. However, to use this form, the short_open_tag INI setting should be enabled. When this tag is enabled, <? also is treated as PHP starting tag, which may be a problem for people using XML in templates, since the engine would confuse XML starting tag with PHP code start.

Proposals

To try and enable people to write short and nice templates, while keeping all XML folks happy, the following solutions were proposed:

Runtime short tags

Make short_open_tags settable in runtime, thus allowing the template engine to turn it on when parsing template, while leaving the opportunity for the user to keep it off outside template parsing.

Always available template tags

Make the tag <?= work even when short_open_tag is off, thus allowing nice templates without breaking the XML templates.

Make other syntax

Make some other short XML-compliant syntax (such as <?:) to be used in templates.