Retrieve values from text file in context of Velocity template?

I’d like to figure out a way to retrieve values from a text (XML or other) file within the bindings or code of a Velocity template. This would be a way to remove some of the literals from our template bindings and code, and store them in files that we can change whenever we want, without making and deploying a code change.

For example, we have a parameter value that we want to add to various URLs on one of our pages, and right now we put that value in a binding in the page template:

$quote_eventid = 69263

(it’s actually in the binding tab, but I’m just using abbreviated syntax here).

If that event ID changes, we need to change our template. It would be nice to just change a value in the Velocity equivalent of a properties or config file.

Has anyone done something like this?

Thanks,
Kathleen

Hi Kathleen

Can you not just use the publishing variables? How many are you talking about?

Cheers
James

The number would be in the ballpark of 10-20 or so.

What do you mean by the “publishing variables”?

What about retrieving values from a database and using tools such as $rx.db.get($db, $query) ?

Thanks for that suggestion. That could be an improvement - we would only need to change a value in a database, rather than a template.

Retrieving from a file on the file system would be even better, because we could have our users maintain it directly (rather than needing a developer to change a value in the database).

[QUOTE=kmbailey;16499]The number would be in the ballpark of 10-20 or so.

What do you mean by the “publishing variables”?[/QUOTE]

In the interface, these are labeled “Context Variables”. You maintain them as part of the Site registration.

Sometimes, these objects are also referred to as “global variables”.

See “Defining Context Variables”, p. 180, in the Rhythmyx Implementation Guide for Version 6.5.2.

Similar to keeping track of variables in one place, you could create a velocity macro that returns the variable value based on what is passed to it. Of course at this point you would just maintain the variables and values in the velocity macro file (so you would still have to promote that to get a change through…but strictly speaking, it is a file :smiley: )

I.E. in the user velocity macro (rx_assembly.vm)


#macro (getValue $varName $returnTxt)
#if($varName.equals("case1"))
#set($returnTxt = "Foo")
#elseif($varName.equals("case2"))
#set($returnTxt = "Bar")
#end
#end

and then you can use it in the template as


#getValue( "case1" $myVar)##
## $myVar should now be set as Foo
$myVar