Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

HTML::Template and Spaces

by Anonymous Monk
on Aug 19, 2013 at 17:57 UTC ( #1050060=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is my first post so feel free to critique me etiquette as well. My problem is the html outfile producing strings cutoff at the first space in the Records Loop. Here's the short program preceding the template it's supposed to fill out:

PROGRAM

#!/usr/bin/env perl use v5.16.3; use strict; use warnings; use autodie; use Data::Dump qw(dump); use HTML::Template; my $template = HTML::Template->new(filename => 'test.tmpl'); open FILE, ">", "output.html"; $template->param(RECORDS => [ {LINENUMBER => "1", CHARACTER => "Sid", TEXT => "this only prints +the first word"}, {LINENUMBER => "2", CHARACTER => "Sid", TEXT => "this only prints +the first word"}, {LINENUMBER => "3", CHARACTER => "Sid", TEXT => "this only prints +the first word"}, ]); print FILE "Content-Type: text/html\n\n", $template->output; close FILE;

HTML Template

<html> <head><title>Test Template</title></head> <body> <h1>The Script</h1> <TABLE><BORDER=5> <TR> <TH>Line No.</TH> <TH>Character</TH> <TH>Text</TH> </TR> <TMPL_LOOP NAME=RECORDS> <TR> <TD> <INPUT TYPE=TEXT NAME=LINENOINPUT VALUE=<TMPL_VAR NAME=LI +NENUMBER> > </TD> <TD> <INPUT TYPE=TEXT NAME=CHARACTERINPUT VALUE =<TMPL_VAR NAM +E=CHARACTER> > </TD> <TD> <INPUT TYPE=TEXT NAME=TEXTINPUT VALUE=<TMPL_VAR NAME=TEXT +> > </TD> </TR> </TMPL_LOOP> <TR> <TD> <INPUT TYPE=TEXT VALUE="This value works"> </TD> </TR> </TABLE> </body> </html>

<INPUT TYPE=TEXT NAME=TEXTINPUT VALUE=<TMPL_VAR NAME=TEXT>

will print out "This"

<INPUT TYPE=TEXT VALUE="This value works">

will print out the full string.

Thanks for your help!

Comment on HTML::Template and Spaces
Select or Download Code
Re: HTML::Template and Spaces
by RichardK (Priest) on Aug 19, 2013 at 18:41 UTC

    Does using quotes for the value help? (I've never used this module so this is just a guess)

    VALUE="<TMPL_VAR NAME=TEXT>"

    HTML::Template has lots of docs with examples ;)

Re: HTML::Template and Spaces
by toolic (Chancellor) on Aug 19, 2013 at 18:46 UTC
    Adding quotes fixes it. Note that I added quotes after all VALUE=, as the POD for HTML::Template shows.
    <html> <head><title>Test Template</title></head> <body> <h1>The Script</h1> <TABLE><BORDER=5> <TR> <TH>Line No.</TH> <TH>Character</TH> <TH>Text</TH> </TR> <TMPL_LOOP NAME=RECORDS> <TR> <TD> <INPUT TYPE=TEXT NAME=LINENOINPUT VALUE="<TMPL_VAR NAME=L +INENUMBER>" > </TD> <TD> <INPUT TYPE=TEXT NAME=CHARACTERINPUT VALUE ="<TMPL_VAR NA +ME=CHARACTER>" > </TD> <TD> <INPUT TYPE=TEXT NAME=TEXTINPUT VALUE="<TMPL_VAR NAME=TEX +T>" > </TD> </TR> </TMPL_LOOP> <TR> <TD> <INPUT TYPE=TEXT VALUE="This value works"> </TD> </TR> </TABLE> </body> </html>
Re: HTML::Template and Spaces
by sundialsvc4 (Monsignor) on Aug 19, 2013 at 18:50 UTC

    Not surprising.   (But, great!)   When in doubt, always look at the actual HTML that is coming out of the template ... not how your browser renders it.   (This HTML was invalid, and browsers are never consistent as to how they handle errors.)   There used to be a really good plug-in for Firefox that could subject any incoming HTML stream to an “HTML lint” to automatically detect invalid constructs coming back from the server.   (It’s great fun to run that on a commercial website... not so much fun to run against your own.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050060]
Approved by Old_Gray_Bear
Front-paged by sparkyichi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-09-18 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (124 votes), past polls