Jump to content
xisto Community
Sign in to follow this  
shiv

Create Easily Modifiable Html Templates For Use In Your Perl Cgis

Recommended Posts




Hate having to place all the print statements in your program and having to escape all those quotes?
Would you like to give the ability for people who don't know how to program in perl to customize the output of your cgis?

Templates are the answer. Here's how it works. Take any html file and anywhere you place in(variable), it gets replaced with $in{'variable'}. For example, if you have $in{'name'} = 'bob' and an html file that has:
Name: in(name)

The output would look like:
Name: shiv


Usage (Step 1):
Use this code to call the subroutine. Replace

&PageOut("


Code (Step 2):

Add the following code somewhere within your script.


sub PageOut{local($file) = @_;open(OUT,"$file")||print "$!: $file<br>";while(<OUT>){$_ =~ s/in\((\w+)\)/$in{$1}/g;print;}close OUT;}

with either a relative or full path to the html template. Example: &PageOut("t_index.htm"); where 't_index.htm' is your template file. Any line that has in(variable) will be replaced with $in{'variable'}



");



njoy!

shiv

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.