|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
frizzo Smarty n00b
Joined: 29 Jul 2003 Posts: 2
|
|
Back to top |
|
CirTap Smarty Pro
Joined: 04 Jun 2003 Posts: 106
|
Posted: Tue Aug 05, 2003 8:21 pm Post subject: |
|
|
Hi,
well first you should have Smarty up and running and find out, if the template directory structure can be handled by Smarty.
I almost forget everything about FastTemplate as I kicked it from my disk soon after I downloaded it (years ago), but I remember it uses similar "tags" for the variables, so you could preg_replace() them (see below), e.g {catrow} should become {$catrow} and {catrow.item}, {$catrow.item}.
You could first make a "dry run" with every .tpl file, by changing the $left_delimiter and $right_delimiter properties of Smarty to some "unusal" characters, that do not exist in the FastTemplates, e.g 'é' and 'è' - don't use any form of parentheses, #, /, \ or other "sourcecode stuff" -- this will certainly fail.
Smarty should then at least spit out the HTML inthe templates without complaining anything.
I think to remember about some sort of "macros" and "block vars", which should be convertable to modifier functions, e.g. where you have sth. like a {menu.top}, preg_replace() this to {menu|block}, write a smarty_modifier_menu() function to handle this instead. A foreach() loop with checks to 'array' and 'object' should do, incl. recursion.
There are other things like
<-- BEGIN menu -->
<html code>
<-- END menu -->
they should transform to {foreach} or {section}
The variable assignment differs a lot, so if you don't want to rewrite all the PHP code, you should write a "wrapper" function/class that takes the FastTemplate arguments and assign() them to the Smarty instance
It'd best to subclass Smarty for that, so you can use $this.
I found some script here which I think is based on the FastTemplate interface.
Your subclass should (at least) implement things like
- pparse() ... calls $this->display()
- assign_var_from_handle() ... calls $this->assign_by_ref()
- assign_block_vars() ... becomes
- assign_vars() ... does a loop with $this->assign($key, $value)
- assign_var() ... calls $this->assign()
- set_rootdir() ... $this->template_dir
- compile() ... candidates for $html = $this->fetch()
- destroy() ... sounds like $this->clear_cache('file.tpl')
Things like Template(), t_filenames(), make_filename(), loadfile() may become dummy functions or simply set some Smarty properties where it makes sense. You can use them to determine filepath as well or to built a "file:/path/dir/filename.tpl" for use with display().
So, these are just some ideas of what I can see on the todo list
A full flavoured converter is probably more than a few lines of code and you need to know both worlds, but it should be a possible task.
For the variable replacements in your old templates I'd write some PHP script(s) reading the tpl-files, and transform the {vars} into {$var}.
I'm not a regexp guru, but I guess this may become a multipass transformation for each type of placeholder, variables, and loops.
Feel free to ask, if there is something I didn't explain well enough.
Have fun,
CirTap |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|