[ic] Very Simple UserTag - Failed Safe Check

Ethan Rowe ethan at endpoint.com
Thu Sep 16 17:31:35 EDT 2004


Adrian P Wilkinson wrote:

> Hi again,
>
> Okay, after taking on the suggestions here (making it so it actually 
> contains Perl; I didn't notice that the UserTag I was using as an 
> example used a >>EOF in it where I saw the raw HTML) I've progressed to:
>
> ================================================================
> UserTag lease-cost      Routine <<EOR
> sub {
>
>  my $a36 = [value item-price]*33.67;
>  my $a60 = [value item-price]*22.50;
>
> return <<EOF;
>
> You could lease this item for only $a36 per month (36 months) or $a60 
> (60 months) ex. VAT.<br>
> <small><em>[ <a href="#">Click Here for Details</a> ]</em></small>
> EOF
>
> }
> EOR
> ================================================================
>
> Called from flypage.html:
>
> "[value item-price]" gives an Internal Server Error
> "[item-price]" fails the safe check.

Adrian, it's not just that the sub must actually contain Perl; it must 
be Perl and nothing else.  You can't use ITL within it.  In Perl, the 
square brackets create an array reference out of the stuff contained 
within; so you're [value item-price]*33.67 call is trying to create an 
array referene and multiply it by a number.

For most everything available in ITL, there's a Perl equivalent.  Most 
ITL tags are called pretty simply in Perl such that [tagname] becomes 
$Tag->tagname().

[value], [scratch], and [cgi] are a little different in that they give 
you values out of different Perl hashes.  If you just want to access the 
value of something, theres a $Values->{...} hash.  The exact calling 
syntax (specifically, the funny characters to use in front of the word 
"Values") differs depending on the scope of the Perl code you're 
writing.  If you're not accustomed to Perl programming this isn't 
impossible by any means but is not an easy thing to leap into.

I suggest taking a look at the tags reference 
(http://www.icdevgroup.org/interchange-doc-5.2.0/ictags.html) and, for 
each ITL tag you're trying to use in your usertag, use the Perl 
equivalent described it.  Furthermore, the reference on Templates 
programming is very helpful regarding standard Perl objects 
(http://www.icdevgroup.org/interchange-doc-5.2.0/ictemplates.html).

If you're doing stuff that could be done entirely in ITL, but you want 
the functionality encapsulated, you have other options.  For instance, 
setting up the ITL routine within a variable allows you to call it; you 
can effectively pass arguments into it using scratch space (via the 
[set], [seti], or [tmp] tags) and include the variable any number of 
times on your page.  This may not be the best way to go, 
performance-wise, but it's another possibility.

-- 
Ethan Rowe
End Point Corporation
ethan at endpoint.com



More information about the interchange-users mailing list