[stringtemplate-interest] if-condition in subtemplates

Sindre Svendby sinsvend at gmail.com
Mon Aug 25 07:29:46 PDT 2008


2008/8/22 Terence Parr <parrt at cs.usfca.edu>:
>
> On Aug 22, 2008, at 5:43 AM, Sindre Svendby wrote:
>
>> Hi, I having problems with if-condition in subtemplate's (template's
>> that invokes other template's)
>>
>> Imagine I _dont_ have a var called nVar and call firstTemplate:
>>
>> ----
>> group templ;
>>
>> firstTemplate() ::= <<
>> $if(!nVar)$
>>   $subTempl(...)$
>> $endif$
>>>>
>
> are you sure nVar is not in the parameter list for firstTemplate?

Im sure, I have replace nVar with other non-real var. names to, it
returns false. Should it return an error?

>
>>
>> subTempl() ::= <<
>> $if(!nVar)$                <--- Reporting
>> java.util.NoSuchElementException: no such attribute: nVar in template
>> context
>>   ..whatever..
>> $endif$
>>>>
>> ----
>>
>> In the StringTemplate Documentation it stand "IF actions test the
>> presence or absence of an attribute unless the object is a Boolean, in
>> which case it tests the attribute for true/false."
>>
>> Is this error intentional? Is there any work-arounds, or have I just
>> no clue about what I'm doing :)
>> I have this problem with StringTemplate Group Files.
>
> Group files enforce attribute definitions whereas template files don't.
>  Can't ref an attr that doesn't exist.
>
> ter
>
ok.

Another really basic question:
basicEks() ::= <<
$int sum = 21;$
$sum$
>>

Shouldn't this have 21 as output?

Sindre


More information about the stringtemplate-interest mailing list