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 ( [id://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

Replies are listed 'Best First'.
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

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 "&#39;".
    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 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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found