TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-17-2007, 09:04 PM   #1 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default Templating class

Alright, I'm struggling to get a template class (smarty like) going on right here, and I've made it, up to some point. Simple vars, like $a, $some_var, $a_v4r and such are correctly parsed by this simple rule: (variables will look like {$this_is_a_var} in the HTML code)

Code:
$this->output = preg_replace( "/\{\$([a-zA-Z0-9_\-]+?)\}/", '$this->vars[\'\\1\']', $this->output );
But, I cannot replace arrays, for some reason. If I try the php syntax, like {$array['index1']['index2']}, the script is complaining about unescaped quotes and stuff like that. I've managed to get a way working (the smarty way - $arr.index1.index2), but still won't work right. So far I've managed to do this (but notice, however, that only the last part of the array is captured - e.g.: $array['a'][0] would output $array[0], no matter how many keys I add there):

Code:
$this->output = preg_replace( "/\{\$([a-zA-Z0-9_\-]+?)(\['?(?:[a-zA-Z0-9]+?)'?\])*\}/e", '$this->vars[\'\\1\']\\2', $this->output );
I store these template vars into an array, component of a class, like so:

Code:
$this->template_vars = array( 'test_var' => 'some sample var',
'array' => array( 'a' => 'test', 1, 2, 3 ) );
Please help me out with some tips, or a direction, anything. Thanks in advance.

Also, if someone has a little free time & knowledge, please try to respond to the last question of this topic: RegEx It would help me alot. Thanks.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 12-29-2007, 04:41 PM   #2 (permalink)
The Visitor
 
Join Date: Dec 2007
Location: Ukraine
Posts: 2
Thanks: 0
dzysyak is on a distinguished road
Default

I can suggest to use php as a template engine. Actually that is reason why php was created. And it works much faster than any template engine.
__________________
Sergiy,
PHP MySQL AJAX website development
dzysyak is offline  
Reply With Quote
Old 12-29-2007, 06:15 PM   #3 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by dzysyak View Post
I can suggest to use php as a template engine. Actually that is reason why php was created. And it works much faster than any template engine.
I've already chosen that instead of what I was trying to do. It's a choice that fits my needs much more better than a separate templating engine (which has many limitations). I used output buffering combined with a very simple class and a few includes to achieve that and it works like a charm. Also, I can take full advantage of PHP, without having to replicate its default functions in any way. But thanks anyways.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:24 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design