Since you’re using Rhythmxy Version 6.5.2, you might also want to consider using the JEXL if operator, which was introduced when we upgraded JEXL in Rhythmyx Version 6.5. The $rx.cond.choose function is deprecated as of Version 6.5.
The if operator works in Velocity as well as JEXL, but I’m having a problem with the condition. For example, this Velocity code displays a heading in my Callout snippet:
#if (1==1)
<h2>#field("displaytitle")</h2>
#end
But this more complex condition gets the error, “Problem assembling output for item: 4-101-881 with template: SnCallout exception: Property rx:usage not found see log for stack trace”:
I just verified that your code seems to work on our system (but I do know there was a point where it did not so I had to do the first way i suggested). We are on 6.5.2.13420.
Eh…i didn’t look at your error…because you are apparently putting this code in SnCallout (which i assume is a snippet) is it possible that another content type using this snippet does not have the rx:usage field?
Using the code dbenua has makes sure the property/field exists, so you probably will not see it get to that point (where velocity fails to find the undefined field)
Problem assembling output for item: 2-101-952 with template: SnCallout exception: Encountered "getProperty" at line 13, column 59.
Was expecting one of:
"[" ...
"(" ...
<STRING_LITERAL> ...
"true" ...
"false" ...
<NUMBER_LITERAL> ...
<IDENTIFIER> ...
"{" ...
"!" ...
see log for stack trace
I made that change and it works great. Or, it works great from Generic pages which actually have the Usage field - which of course SnCallout does not. Maybe I need $sys.the.other.item.getProperty(“rx:usage”).String.equals(‘L’))!
I don’t understand this statement. The #if statement will be “false” whenever you assemble an item which does not contain the “usage” field. You need to handle this in the #else condition.
Do you want to clarify exactly what your goal is here?
I was sort of making a joke about my coding abilities or lack of them. Goal: if a callout snippet is contained in a slot on a Landing page (a page for which usage==L), I want to display a header above the callout body. Is there a function that can be included in a snippet that checks a condition in the content type that contains the snippet, not a condition in the snippet itself?
Not directly. You cannot reference the “properties” of the containing node. However, you can set a binding variable (in the bindings tab) of the containing (page) template, and reference this binding variable in the snippet code.
You need to make sure that the variable has a name that will not cause it to be overwritten (e.g. don’t use one of the standard $sys variables).
You also need to set the variable in the binding tab and not in the Velocity source. Otherwise, it will not be visible to the snippet.
Lastly, you need to be prepared for the variable to be null, as it will not be defined when you preview the snippet, or include the snippet in another slot.
Agreed, but I believe the concern is over what happens when the $usage variable is undefined? I’m not sure if velocity throws an error of whether it is just a warning. In any case, if you check to make sure that the field exists (as per dbenua’s code) using $sys.item.hasProperty(“rx:usage”) you would get by any null declarations (so you could use the SnCallout snippet with content types that don’t necessarily have the usage field defined…just makes for a reusable snippet template).