473,408 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

how to loop in templates?

having developed this simple template engine for my own projects,the
engine simply replaces the {replacable} tags with the appropriate
value.
the template file is read into a string variable $string ,then i use
preg_replace_callback to process the tags.
now,i have a problem with the loops.i've though about this:

{LOOP_NAME}
things to be {repeated}
{/LOOP}

then i though about using preg_replace_callback twice,once to extract
the loop body,repeat it then insert it back into $string.
then use the final preg_replace_callback to replace all {replacable}
variables.
is this a bad idea for server loads?

Apr 24 '07 #1
1 1548
me******************@gmail.com wrote:
having developed this simple template engine for my own projects,the
engine simply replaces the {replacable} tags with the appropriate
value.
the template file is read into a string variable $string ,then i use
preg_replace_callback to process the tags.
now,i have a problem with the loops.i've though about this:

{LOOP_NAME}
things to be {repeated}
{/LOOP}

then i though about using preg_replace_callback twice,once to extract
the loop body,repeat it then insert it back into $string.
then use the final preg_replace_callback to replace all {replacable}
variables.
is this a bad idea for server loads?
I did something similar, and it took me a while to get it to work right, but I didn't have it working for long enough to get an idea of server loads. I now use Smarty template engine because it has more advanced features than I had time to make myself. It didn't seem THAT slow, but I remember wishing it were faster.

-Mike PII
Apr 25 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: b0yce | last post by:
Hi all, I am trying to create a recursive loop transformation that remembers last position of inner loop so that it continues from that point instead of the point from where the recursion...
1
by: rosemm | last post by:
Hi. I am new to XML. I am working on a pretty simple problem at the moment but can't seem to figure out what I am doing wrong. I am trying to print the last nameof every member listed in my...
354
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets...
32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
3
by: Richard Cavell | last post by:
I have a recursive function like this: void MyFunction(int i) { i++; // do something with i if (we're not finished) MyFunction(i); } I keep count of how far nested we are with i. Now, it...
3
by: deko | last post by:
Problem: why doesn't this With block work? is it possible to have a For Each loop within a With block? With objWord .Documents.Add Template:=strTemplate, NewTemplate:=False, DocumentType:=0...
24
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was...
2
by: davidw | last post by:
I have flat xml like this <field name="a1"/> <field name="a2" merge="true"/> <field name="a3"/> <field name="a4"/> <field name="a5" merge="true"/> <field name="a6" merge="true"/> <field...
2
by: kuttankuttan | last post by:
how can i convert the following XML __________________________________________________ <?xml version="1.0" encoding="UTF-8"?> <object type="company" action="C"> <property name="howmanynumbers"...
2
by: erikcw | last post by:
Hi all, I'm trying to write a loop that will build a list of "template strings". My current implementation is *really slow*. It took 15 minutes to finish. (final len(list) was about 16k...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.