Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Two Template Toolkit questions

by nop (Hermit)
on Feb 23, 2002 at 17:03 UTC ( #147081=perlquestion: print w/ replies, xml ) Need Help??
nop has asked for the wisdom of the Perl Monks concerning the following question:

Two small questions on TT2:
  • How do I escape apostrophes? eg I'd like have a proper apostrophe in the word "dont" in this code:
    [% header(title='Dont try this') %]
  • How do I use a TT2 variable in a TT2 function call? eg if  [% c1 %] is a TT2 variable, how do I do something like this?
    [% CGI.textfield(name =>"copy1", size=>50, maxlength=>50, default=>c1) +%]
    The code above breaks the quote.
Thanks
nop

Comment on Two Template Toolkit questions
Select or Download Code
Re: Two Template Toolkit questions
by nop (Hermit) on Feb 23, 2002 at 17:12 UTC
    Well, after scratching my head a bit, I realized the second one is fine. It looked broken (it wasn't) because  c1 was coming from a database field and was right-packed with spaces -- almost 1200 of them.

    Still wondering about my 1st question, tho

    nop
Re: Two Template Toolkit questions
by Dog and Pony (Priest) on Feb 23, 2002 at 17:29 UTC
    I admit I haven't used this module, but you have tried 'Don\'t try this'? If you are looking for the HTML escape though, I think it is "'".
    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
Re: Two Template Toolkit questions
by lachoy (Parson) on Feb 23, 2002 at 19:27 UTC

    Just like Perl, you can use single or double quotes:

    #!/usr/bin/perl use strict; use Template; my $template = Template->new(); $template->process( \*DATA, { runme => sub { return "<$_[0]->{title}>" } } ); __DATA__ [% runme( title = "don't try this" ) %]

    Produces:

    <don't try this>

    Chris
    M-x auto-bs-mode

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-12-25 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (161 votes), past polls