rb:eval
This attribute behaves in a very similar way to the
<rb:eval...> tag. The 'value' part of the attribute is a JavaScript
expression that is evaluated by the presentation engine. The result of the
evaluation is then substituted for the attribute. The syntax for the expression
has one modification over the tag variant. The syntax can be summarised as:
'[new attribute name#]JavaScript Expression'
The 'new attribute name' is optional. If present it is followed by a '#'
delimiter and then the JavaScript expression. There are two cases to consider:
name present; name absent.
Name Present
If the name is present then the entire 'rb:eval' attribute is replaced with
name=expression_result. That is the JavaScript expression is evaluated
and the result used as the value part of the replacement attribute. The name
is taken from the string before the '#'.
Example
<a rb:eval="href#session.homepage()">Home
Page</A>
...assuming 'session.homepage()' returns 'petespage.htm' the Presentation
Engine will translate this tag into:
<a href="petespage.htm">Home Page</A>
Note: The
Presentation Engine wraps the value returned from the JavaScript expression
in double quotes. There is no need for the expression itself to do this,
however if the expression can itself contain quotes then it should be escaped
using the JavaScript 'escape' method. Name Missing If the name is not specified in the expression string the Presentation
Engine simply evaluates the JavaScript expression and uses the results as the
raw replacement for the tag. It is the responsibility of the script to generate
all the elements of the replacement attribute
Example
<a
rb:eval="'href="'+session.homepage()+'"'">
Home Page</A>
...assuming 'session.homepage()' returns 'petespage.htm' the Presentation
Engine will translate this tag into:
<a href="petespage.htm">Home Page</A>
In this case the expression needs to include double quotes, these can be included
using the " sequence. The Presentation Engine 'unescapes'
the string provided before giving the string the JavaScript engine.
Note also how double and single quotes are used to generate the URL.
|