Really simple Smartys?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Really simple Smartys?

Post by Todd_Z »

Has anyone developed a really simple version of smarty? Meaning just iterative sections and variables - I don't want to have such a complicated template system - creates too much overhead in size and loading time.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

depending on your needs, a simple regex can perform the task quite fast.. unless you need logic controls.. then it gets a bit hairy, quickly.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

I'm pretty sure that I can strip the code down to simple foreach statements... How would i do it with regexs?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

store that template block in a seed string, loop over the block list sending the current data through the regex along with the seed string. Store the result into your output buffer or simply echo if no further processing is needed.

I use preg_replace() and the 'e' (evaluate) modifier to do this in my streamlined template engines.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

uh.... I'm not a n00b or anything - but I still have no idea what you just said :cry: Especially about a seed string <- whats that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Store the template block into a string. This string is not to be changed throughout the processing of the block. You simply pass that string as the text to run the regex on.

¿comprenda?
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

http://www.acdrifter.com/Templates/Reviews-Template.php

I guess that would be the block that doesn't change.

Every variable with the name "Page____" would be a static variable.
Reviews would be an array of objects
Review would be an object with variables to access - I figure that accessing variables instead of calling methods would be easier for me at this point.

So now that I have that, what kind of regex would iterate over that section?
Post Reply