Forums/New Features

<w:var> enhancements

Christopher Haupt
posted this on June 29, 2011, 17:43

WebvantaScript's variable tag (e.g. <w:var name="my_variable">) allows you to capture a value that can subsequently be used in other WebvantaScript tag attributes. Until now, the content stored in the variable alway came from the value attribute or the text between the opening and closing <w:var> tags.

Two new enhancements give you access to additional content:

  1. Using the param="key name" attribute will attempt to read a query parameter from the current page's URL. If the param does not exist, the variable will be assigned the value between its opening and closing tags. If that is also empty, the variable will use the content from the "value" attribute as a default value.
  2. When using the value of a variable (with the {{my_variable}} syntax), if the value is empty from any of the means described in #1, the system will try to use the name of the variable to look up a value in your Global Settings. You can use this for easy access to Global Settings in WebvantaScript conditional attributes, for instance, or as a way of specifying a global default value.
 

Comments

User photo
cmq

Christopher - could you provide a couple of examples, please? 

January 2, 2012, 16:16
User photo
Christopher Haupt
Webvanta

If you have a URL with a parameter:

http://www.webvanta.com/team?person=chris

You can capture the person parameter from WebvantaScript with

<w:var name="the_person" param="person">No one</w:var>

This technique is most useful when trying to pass some short-term information between pages, and the recipient page using the param is a non-cached (Ajax) page. You could, for instance pass an ID of an item, and then consume that ID to create an item context:

http://www.example.com/my_ajax_page?item_id=12345

Then on the my_ajax_page have some wscript like:

<w:kb:item id="{{item_id}}" >

</w:kb:item>

If perhaps you always wanted some default value for that item, you could create a system config with the same name "item_id" and set that to value that would then be used as a "default" if they parameter was NOT passed in the URL.

January 3, 2012, 16:24