I am a first time poster so please be gentle.
Basically I am writing a lightweight templating application.
I want to be able to let html coders link templates together by adding a tag like:
<% link_name faq_template %>
and have this replaced with the appropriate a href based on a lookup of the link name "faq_template" in the database.
The output will look something like:
<a href="http://www.somedomain.com/?q_act=view&q_srn=1719">
Where 1719 is the template_id that corresponds with the faq_template -- After which mod_perl handles the rest :-)
Anyway, not to get too heavily involved in the architecture, I'm slurping up the template that contains
the <%link_name tag into $$file. I take advantage of code evaluation in my regexp
(which also makes sure all the tags are formatted the same way) and do something like the following:
========================
##BEGIN preparse
#makes use of experimental code evaluation regexp features in
+perl
my @link_names;
$$file =~ s/<%[ ]*link_name[ ]*([^ ]*)[ ]*%>(?{push(@link_name
+s,$1);})/<% link_name $1%>/g;
#printStruct(\@link_names); #debugging
#now map link names to actual variables
my $sql;
foreach my $link_name (@link_names){
$link_name=$dbh->quote($link_name);
$sql="SELECT template_id FROM template_table where template_
+name=$link_name";
#print "SQL is $sql \n";
#if success do another regexp find and replace with real url
+
#otherwise replace template tag with HTML code comment indic
+ating error
}#end foreach
##END preparse
===========================
This works fine. The @link_names array is populated
correctly. My only concern is that code evaluation is
indicated in the docs as a very experimental thing.
Will this be deprecated in the future or should I not worry about it?
Rodney A. Hampton
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.