![]() |
| HTML templating |
|
spandox
|
I have been asked a couple of times how to have perl just do some search and replaces in an html document. So that you can make your html in dreamweaver or something and put in a code for the "dynamic" part.
Example template:
I know it is not complex - But what the hey - it is an example I wanted to be able to replace [things] with other bits - generated from code. So lets say I make a hash:
Why not be able to automatically generate the html:
Here is a module I wrote to help with the process:
and an example of it in use
ND is is for no default - If I wanted to put a default in for when there is no key defined I can use the non-ND one. If I want a list of keys from a file I can use getSources Let me know if this is useful to anyone |
||||||||||||||||||||||
|
|
|||||||||||||||||||||||
|
spandox
|
Oh - don't forget to print a content-type is using it as a perl script:
|
||||||||||||||
|
|
|||||||||||||||
| Almost |
|
spandox
|
Not quite the same. The OBJECT tag creates an iframe withing the document. This is essentially a whole new embedded web browser. Not only CAN you put a complete HTML document in - YOU MUST. Style sheets etc do not propigate. This is not a big deal - just re-link the sytle sheet from within code. The big deal is that neither do the values passed to the called document with a POST or GET from a form.
The object tag is good for a static page that has a small portion of dynamic content that is not interactive - or to do a framed skin around a user interface, but it is quite difficult to use to build an application with it (as in anything other than a border - it is just a frame) When working with my artists what I will often do is have them make html mock-ups of what they want. I make a template directory. In this directory the all of the static portions of the code get placed. A perl script opens up a template and build the form (login-in screen, or personal preferences or whatever) and spits it out to the web browser. If the artist ever wants to "reskin" the application they just change the templates. Sometimes the [replaced text] is just a word or two - sometimes it is rows in a table - sometimes it is form elements. If all you want to do is add a username after the world "Hello" on the top of a website creating a frame is just plain silly. Likewise creating a big application that has many interactive elements that has a contigious look and feel with the site trying to put all of the dynamic portion in iframes (or OBJECT tags) is just not a task I would want to undertake. |
||||||||||||
|
|
|||||||||||||
| HTML templating |
|
||
|


