Is there something specificly SMARTY-like you're trying to do?
Only I can't see any relevant benefit in using obscure PHP-like syntax for this.
I would d suggest just using regular variables and packaged custom tags, eg:
<t:section name="sec1" loop="contacts">
phone: #phone#<br/>
fax: #phone#<br/>
cell: #phone#<br/>
</t:section>
(Although I must point out anyone actually using BRs there should be shot)
Which should allow for much nicer syntax, as well as (potentially) DTD checking
to ensure templates are valid.
> I am in need of a template engine similar to Smarty (PHP) for
> ColdFusion? I have not found such a thing yet. Does it exist?
>
> If not, how would you go about writing a parser in ColdFusion that
> could take a template like this ...
>
> --------------------------------------------------
>
> The current date and time is {$smarty.now|date_format:"%Y-%m-%d
> %H:%M:%S"}
>
> The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
>
> Example of accessing server environment variable SERVER_NAME: {$smarty.
> server.SERVER_NAME}
>
> The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
>
> variable modifier example of {ldelim}$Name|upper{rdelim}
>
> <b>{$Name|upper}</b>
>
> {section name=sec1 loop=$contacts}
> phone: {$contacts[sec1].phone}<br>
> fax: {$contacts[sec1].fax}<br>
> cell: {$contacts[sec1].cell}<br>
> {/section}
>
> --------------------------------------------------
>
....
> and turn it into CFML like this ...
>
> --------------------------------------------------
>
> The current date and time is <cfoutput>#dateFormat(Now(), 'y-m-d')#
> #timeFormat(Now(), 'H:m:s')#</cfoutput>
>
> The value of global assigned variable $SCRIPT_NAME is
> <cfoutput>#SCRIPT_NAME#</cfoutput>
>
> Example of accessing server environment variable SERVER_NAME:
> <cfoutput>#CGI.SERVER_NAME#</cfoutput>
>
> <cfoutput>The value of #config.ldelim#$Name#config.rdelim# is
> <b>#config.Name#</b></cfoutput>
>
> <cfoutput>variable modifier example of #config.
> ldelim#$Name|upper#config.rdelim#</cfoutput>
>
> <cfoutput><b>#ucase(name)#</b></cfoutput>
>
> <cfloop from="1" to="#arrayLen(contacts)#" index="contactPtr">
> <cfoutput>phone: #contacts[contactPtr].phone#<br></cfoutput>
> <cfoutput>fax: #contacts[contactPtr].fax#<br></cfoutput>
> <cfoutput>cell: #contacts[contactPtr].cell#<br></cfoutput>
> </cfloop>
>
> --------------------------------------------------
>
> Regular expression find/replace comes to mind first, but I am
> obviously looking for the best performance as well.
>
> Any suggestions?
>
> Thanks.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:258521
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4