<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Using Velocity</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>Using Velocity</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity</link><pubDate>Wed, 05 Aug 2020 16:16:23 GMT</pubDate><guid isPermaLink="false">3d8b9043-6f89-469f-a437-4e17fba4ac00</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity#comments</comments><description>Current Revision posted to Developer Training by Former Member on 08/05/2020 16:16:23&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;Widget content is implemented using a version of the Velocity templating language.&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_the_Velocity_templating_language" name="When_should_I_use_the_Velocity_templating_language"&gt;&lt;/a&gt;When should I use the Velocity templating language?&lt;/h2&gt;
&lt;p&gt;Velocity is one of the two languages used to implement server side [[Scripting|scripts]] used by scripted customizations. Velocity is a templating language best suited to conditional rendering of content to form a string (for example, the HTML rendering of a [[Widgets|widget]]) whereas [[Using Server-side Javascript|Server-side Javascript]] is better suited for data processing. Velocity has full access to the Widget/Scripting API to interact with the Verint Community platform.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Velocity_Language_Syntax" name="Velocity_Language_Syntax"&gt;&lt;/a&gt;Velocity Language Syntax&lt;/h2&gt;
&lt;h3&gt;&lt;a name="Variables_Properties_and_Methods"&gt;&lt;/a&gt;Variables, properties, and methods&lt;/h3&gt;
&lt;h4 id="variables_and_extensions"&gt;&lt;a name="Variables_and_Extensions"&gt;&lt;/a&gt;Variables and extensions&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Variable and extension names must start with a dollar sign and an alphabetic letter.&lt;/p&gt;
&lt;p&gt;When the value of the variable is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$variable&lt;/span&gt; will render the name of the variable and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!variable&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${variable}&lt;/span&gt; is the formal notation for variables and distinguishes variable references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${variable}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Properties"&gt;&lt;/a&gt;Properties&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference properties on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the value of the property is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Property&lt;/span&gt; will render the name of the extension and property and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Property&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Property}&lt;/span&gt; is the formal notation for properties and distinguishes property references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Property}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Methods"&gt;&lt;/a&gt;Methods&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*([optional_parameter_list])[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference methods on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the return value of the method is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Method()&lt;/span&gt; will render the name of the extension and method and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Method()&lt;/span&gt; will render nothing. If the return value is void, nothing will be rendered.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Method()}&lt;/span&gt; is the formal notation for methods and distinguishes method references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Method()}this&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a name="Directives"&gt;&lt;/a&gt;Directives&lt;/h3&gt;
&lt;h4 id="set"&gt;&lt;a name="set"&gt;&lt;/a&gt;#set&lt;/h4&gt;
&lt;pre&gt;#set($reference = [argument])&lt;/pre&gt;
&lt;p&gt;Assigns a value to a variable or property where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$reference&lt;/span&gt; is a variable or property reference.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a method, variable, or property reference&lt;/li&gt;
&lt;li&gt;a literal boolean (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;true &lt;/span&gt;or &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;false&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal number (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[0-9]*.[0-9]*&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal string in single or double quotes&lt;/li&gt;
&lt;li&gt;an array definition (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[$item1, $item2, $item3,... $itemN]&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a mathematic expression:&lt;/li&gt;
&lt;li&gt;Addition: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n + 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Subtraction: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n - 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Multiplication: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n * $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Division: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n / $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Modulus:&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; #set($n = $n % $x)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument] &lt;/span&gt;is a literal string, strings in double quotes will be parsed whereas strings in single quotes will not be parsed.&lt;/p&gt;
&lt;div class="documentation-member"&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="store" name="store"&gt;&lt;/a&gt;#store&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#store($reference)&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the value assigned to the variable]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Assigns the result of executing a block of script to a variable where&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$reference&lt;/span&gt;&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a variable reference.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="code"&gt;#store($result)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;a href=&amp;quot;$user.ProfileUrl&amp;quot;&amp;gt;$user.DisplayName&amp;lt;/a&amp;gt;&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="if"&gt;&lt;/a&gt;#if&lt;/h4&gt;
&lt;pre&gt;#if([condition])&lt;br /&gt;&amp;nbsp; [script to execute when if condition is true]&lt;br /&gt;[&lt;br /&gt;#elseif([condition])&lt;br /&gt;&amp;nbsp; [script to execute when elseif condition is true]&lt;br /&gt;]*&lt;br /&gt;[&lt;br /&gt;#else&lt;br /&gt;&amp;nbsp; [script to execute if no conditions are true]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Conditionally renders templates where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[condition]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a Boolean expression:
&lt;ul&gt;
&lt;li&gt;Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x == $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt; $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt; 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;a non-Boolean variable, property, method, or literal reference (true if not null, otherwise false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="margin:0;padding:0;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="foreach"&gt;&lt;/a&gt;#foreach&lt;/h4&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;[#each]&lt;br /&gt;&amp;nbsp; [script to execute for each item]&lt;br /&gt;[&lt;br /&gt;#before&lt;br /&gt;&amp;nbsp; [script to execute before each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#after&lt;br /&gt;&amp;nbsp; [script to execute after each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#between&lt;br /&gt;&amp;nbsp; [script to execute between each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#odd&lt;br /&gt;&amp;nbsp; [script to execute for every other item, including the first]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#even&lt;br /&gt;&amp;nbsp; [script to execute for every other item, starting with the second]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#nodata&lt;br /&gt;&amp;nbsp; [script to execute if $items is null or empty]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#beforeall&lt;br /&gt;&amp;nbsp; [script to execute before all items, if there are items]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#afterall&lt;br /&gt;&amp;nbsp; [script to execute after all items, if there are items]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Renders templates for each item within a collection of items where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$item&lt;/span&gt; is the variable containing each item in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; collection when executing &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt;, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#odd&lt;/span&gt;, and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#even&lt;/span&gt; scripts.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; is a variable, property, or method resulting in a collection of items.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...] &lt;/span&gt;is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt; is the default template, so,&lt;/p&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;is equivalent to&lt;/p&gt;
&lt;pre&gt;#foreach ($item in $items)&lt;br /&gt;#each&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="format" name="format"&gt;&lt;/a&gt;#format&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#format($formatString)&lt;br /&gt;[#token()]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the numeric token's value]&lt;br /&gt;[#token($parameterName)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the named token's value]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Inserts token values into a tokenized format string where:&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$formatString&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;is the expression resulting in a string containing zero-based numeric (&lt;code&gt;{0}&lt;/code&gt;) or named (&lt;code&gt;{name}&lt;/code&gt;) tokens. The format string cannot mix numeric and named tokens.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Token values are defined using one or more&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;directives within the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#format&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;block. Each&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;can optionally identify a token name.&lt;/p&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{0}, {1}, and {2}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{a}, {b}, and {c}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;a&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;b&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;c&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="registerEndOfPageHtml"&gt;&lt;/a&gt;#registerEndOfPageHtml&lt;/h4&gt;
&lt;pre&gt;#registerEndOfPageHtml([key])&lt;br /&gt;&amp;nbsp; [script to render at the bottom of the completed HTML page]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Registers a block of HTML at the end of the completed HTML page where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is an optional variable, property, or literal string value identifying the unique key with which the contained markup should be registered.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is not supplied, the contained script will always be added to the bottom of the completed HTML page. If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is supplied, the first &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#registerEndOfPageHtml&lt;/span&gt; directive executed will have its contained script added to the bottom of the completed page.&lt;/p&gt;
&lt;h4&gt;&lt;a name="evaluate"&gt;&lt;/a&gt;#evaluate&lt;/h4&gt;
&lt;pre&gt;#evaluate($script)&lt;/pre&gt;
&lt;p&gt;Execute a string as a Velocity script where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$script&lt;/span&gt; is a variable, property, or literal string containing Velocity script.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="stop"&gt;&lt;/a&gt;#stop&lt;/h4&gt;
&lt;pre&gt;#stop&lt;/pre&gt;
&lt;p&gt;Stops execution of the widget immediately.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#stop&lt;/span&gt; should only be used for debugging purposes. To hide a widget, use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$core_widget.Hide() &lt;/span&gt;instead.&lt;/p&gt;
&lt;h4&gt;&lt;a id="T_931095879" name="T_931095879"&gt;&lt;/a&gt;##&lt;/h4&gt;
&lt;pre&gt;## [comment]&lt;/pre&gt;
&lt;p&gt;Identifies a comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is a single line of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a id="T_755172541" name="T_755172541"&gt;&lt;/a&gt;#*&lt;/h4&gt;
&lt;pre&gt;#* [comment lines] *#&lt;/pre&gt;
&lt;p&gt;Identifies a multi-line comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is one or more lines of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_with_Velocity" name="Widget_Extension_Usage_with_Velocity"&gt;&lt;/a&gt;Widget Extension Usage with Velocity&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to velocity script, implemented as a set of widget extensions automatically available in the context of an executed Velocity script. Additionally, custom extensions can also be accessed.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;p&gt;When a widget extension method accepts a dictionary of options, those options can be passed using the Velocity syntax&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;%{ Key1 = $value1, Key2 = $value2 }&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the entire dictionary is passed as a formatted string.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Retrieve the current blog. If there is none, hide the widget
#set ($currentBlog = false)&lt;br /&gt;#set ($currentBlog = $core_v2_blog.Current)
#if (!$curentBlog)
	$core_v2_widget.Hide()
#end

## Retrieve the 5 latest blog posts
#set ($blogPosts = $core_v2_blogPost.List(&amp;quot;%{ BlogId = $currentBlog.Id, PageSize = 5 }&amp;quot;))

#foreach ($blogPost in $blogPosts)
#beforeall
	&amp;lt;ul&amp;gt;
#each
		&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;$core_v2_encoding.HtmlAttributeEncode($blogPost.Url)&amp;quot;&amp;gt;$blogPost.Title&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
#afterall
	&amp;lt;/ul&amp;gt;
#nodata
	&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;
#end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3 id="getting_the_current_foreach_index"&gt;&lt;a name="Getting_the_current_foreach_index"&gt;&lt;/a&gt;Getting the current Foreach Index&lt;/h3&gt;
&lt;p&gt;If you want to track the current index you will need to store the index as a local variable.&amp;nbsp; Here is an example of how you can do this.&lt;/p&gt;
&lt;pre&gt;#set($index = 0)
#foreach($tag in $core_v2_tags.Current)
  #each
	 #set($index = $index + 1)
#end
&lt;/pre&gt;
&lt;h3 id="concatenating_strings"&gt;Concatenating strings&lt;a name="Gotcha_NVelocity_Macros_with_Bodies"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="color:#444444;font-weight:normal;"&gt;Oftentimes you will need to combine two or more strings and pass the result as a parameter to a method, to do this, place the variables within double quotes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;#set($newVal = &amp;quot;$val1$val2&amp;quot;)&lt;/pre&gt;
&lt;h3 id="adding_a_variable_to_the_end_of_a_url_before_a_period"&gt;&lt;a name="Adding_a_variable_to_the_end_of_a_URL_before_a_period"&gt;&lt;/a&gt;Adding a variable to the end of a URL before a period&lt;/h3&gt;
&lt;p&gt;You may need to pass a Velocity variable as part of a URL, and you may need to pass it at the end of the URL before a period.&amp;nbsp; For example, if you are creating a URL for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;api.ashx/v2/groups/$groupId/members/users/$userId.json&lt;/span&gt; where &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; is a local Velocity variable, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; will not be formatted correctly because it is looking for a property named json on &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt;.&amp;nbsp; To get around this, you can use the strict formatting option for Velocity variables, like the following&lt;/p&gt;
&lt;pre&gt;api.ashx/v2/groups/$groupId/members/users/${userId}.json&lt;/pre&gt;
&lt;h3 id="gotcha_cannot_set_a_null_value"&gt;&lt;a name="Gotcha_Cannot_set_a_null_value"&gt;&lt;/a&gt;Working with null values&lt;/h3&gt;
&lt;p&gt;When Velocity evaluates&lt;/p&gt;
&lt;pre&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;if&amp;nbsp;$someExtension.someMethod()&amp;nbsp;evaluates to&amp;nbsp;null,&amp;nbsp;$variable&amp;nbsp;will not be changed. It will still have its previous value. To reuse the&amp;nbsp;$variable&amp;nbsp;variable (in a&amp;nbsp;#foreach, for example), instead use:&lt;/p&gt;
&lt;pre&gt;#set ($variable = false)&lt;br /&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;This is how links widgets must be implemented.&amp;nbsp;&lt;/p&gt;
&lt;h3 id="programmatically_modifyingbuilding_dictionary_options"&gt;&lt;a name="Programmatically_Modifying_Building_IDictionary_Options"&gt;&lt;/a&gt;Programmatically modifying/building dictionary options&lt;/h3&gt;
&lt;p&gt;It is already possible to do calls like this&lt;/p&gt;
&lt;pre&gt;$core_v2_foo.Bar(42, &amp;quot;%{ key1 = &amp;quot;value&amp;quot;, key2 = &amp;quot;value2&amp;quot; }&lt;/pre&gt;
&lt;p&gt;Sometimes it is necessary to programmatically build the options dictionary for looping or logical reasons. This can be done as follows:&lt;/p&gt;
&lt;pre&gt;#set ($options = &amp;quot;%{}&amp;quot;)
$options.Add(newKey, &amp;quot;newValue&amp;quot;)&lt;/pre&gt;
&lt;p&gt;Try&amp;nbsp;&lt;code&gt;$core_help.Dump()&lt;/code&gt;ing&amp;nbsp;&lt;code&gt;$options&lt;/code&gt;&amp;nbsp;to see the full set of methods available for operating on the dictionary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: velocity, widgets&lt;/div&gt;
</description></item><item><title>Using Velocity</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity/revision/6</link><pubDate>Fri, 21 Jun 2019 20:19:34 GMT</pubDate><guid isPermaLink="false">3d8b9043-6f89-469f-a437-4e17fba4ac00</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity#comments</comments><description>Revision 6 posted to Developer Training by Ben Tiedt on 06/21/2019 20:19:34&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;Widget content is implemented using a version of the Velocity templating language.&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_the_Velocity_templating_language" name="When_should_I_use_the_Velocity_templating_language"&gt;&lt;/a&gt;When should I use the Velocity templating language?&lt;/h2&gt;
&lt;p&gt;Velocity is one of the two languages used to implement server side [[Scripting|scripts]] used by scripted customizations. Velocity is a templating language best suited to conditional rendering of content to form a string (for example, the HTML rendering of a [[Widgets|widget]]) whereas [[Using Server-side Javascript|Server-side Javascript]] is better suited for data processing. Velocity has full access to the Widget/Scripting API to interact with the Verint Community platform.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Velocity_Language_Syntax" name="Velocity_Language_Syntax"&gt;&lt;/a&gt;Velocity Language Syntax&lt;/h2&gt;
&lt;h3&gt;&lt;a name="Variables_Properties_and_Methods"&gt;&lt;/a&gt;Variables, properties, and methods&lt;/h3&gt;
&lt;h4 id="variables_and_extensions"&gt;&lt;a name="Variables_and_Extensions"&gt;&lt;/a&gt;Variables and extensions&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Variable and extension names must start with a dollar sign and an alphabetic letter.&lt;/p&gt;
&lt;p&gt;When the value of the variable is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$variable&lt;/span&gt; will render the name of the variable and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!variable&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${variable}&lt;/span&gt; is the formal notation for variables and distinguishes variable references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${variable}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Properties"&gt;&lt;/a&gt;Properties&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference properties on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the value of the property is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Property&lt;/span&gt; will render the name of the extension and property and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Property&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Property}&lt;/span&gt; is the formal notation for properties and distinguishes property references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Property}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Methods"&gt;&lt;/a&gt;Methods&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*([optional_parameter_list])[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference methods on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the return value of the method is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Method()&lt;/span&gt; will render the name of the extension and method and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Method()&lt;/span&gt; will render nothing. If the return value is void, nothing will be rendered.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Method()}&lt;/span&gt; is the formal notation for methods and distinguishes method references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Method()}this&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a name="Directives"&gt;&lt;/a&gt;Directives&lt;/h3&gt;
&lt;h4 id="set"&gt;&lt;a name="set"&gt;&lt;/a&gt;#set&lt;/h4&gt;
&lt;pre&gt;#set($reference = [argument])&lt;/pre&gt;
&lt;p&gt;Assigns a value to a variable or property where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$reference&lt;/span&gt; is a variable or property reference.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a method, variable, or property reference&lt;/li&gt;
&lt;li&gt;a literal boolean (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;true &lt;/span&gt;or &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;false&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal number (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[0-9]*.[0-9]*&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal string in single or double quotes&lt;/li&gt;
&lt;li&gt;an array definition (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[$item1, $item2, $item3,... $itemN]&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a mathematic expression:&lt;/li&gt;
&lt;li&gt;Addition: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n + 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Subtraction: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n - 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Multiplication: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n * $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Division: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n / $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Modulus:&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; #set($n = $n % $x)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument] &lt;/span&gt;is a literal string, strings in double quotes will be parsed whereas strings in single quotes will not be parsed.&lt;/p&gt;
&lt;div class="documentation-member"&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="store" name="store"&gt;&lt;/a&gt;#store&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#store($reference)&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the value assigned to the variable]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Assigns the result of executing a block of script to a variable where&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$reference&lt;/span&gt;&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a variable reference.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="code"&gt;#store($result)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;a href=&amp;quot;$user.ProfileUrl&amp;quot;&amp;gt;$user.DisplayName&amp;lt;/a&amp;gt;&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="if"&gt;&lt;/a&gt;#if&lt;/h4&gt;
&lt;pre&gt;#if([condition])&lt;br /&gt;&amp;nbsp; [script to execute when if condition is true]&lt;br /&gt;[&lt;br /&gt;#elseif([condition])&lt;br /&gt;&amp;nbsp; [script to execute when elseif condition is true]&lt;br /&gt;]*&lt;br /&gt;[&lt;br /&gt;#else&lt;br /&gt;&amp;nbsp; [script to execute if no conditions are true]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Conditionally renders templates where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[condition]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a Boolean expression:
&lt;ul&gt;
&lt;li&gt;Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x == $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt; $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt; 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;a non-Boolean variable, property, method, or literal reference (true if not null, otherwise false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="margin:0;padding:0;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="foreach"&gt;&lt;/a&gt;#foreach&lt;/h4&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;[#each]&lt;br /&gt;&amp;nbsp; [script to execute for each item]&lt;br /&gt;[&lt;br /&gt;#before&lt;br /&gt;&amp;nbsp; [script to execute before each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#after&lt;br /&gt;&amp;nbsp; [script to execute after each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#between&lt;br /&gt;&amp;nbsp; [script to execute between each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#odd&lt;br /&gt;&amp;nbsp; [script to execute for every other item, including the first]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#even&lt;br /&gt;&amp;nbsp; [script to execute for every other item, starting with the second]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#nodata&lt;br /&gt;&amp;nbsp; [script to execute if $items is null or empty]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#beforeall&lt;br /&gt;&amp;nbsp; [script to execute before all items, if there are items]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#afterall&lt;br /&gt;&amp;nbsp; [script to execute after all items, if there are items]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Renders templates for each item within a collection of items where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$item&lt;/span&gt; is the variable containing each item in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; collection when executing &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt;, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#odd&lt;/span&gt;, and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#even&lt;/span&gt; scripts.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; is a variable, property, or method resulting in a collection of items.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...] &lt;/span&gt;is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt; is the default template, so,&lt;/p&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;is equivalent to&lt;/p&gt;
&lt;pre&gt;#foreach ($item in $items)&lt;br /&gt;#each&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="format" name="format"&gt;&lt;/a&gt;#format&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#format($formatString)&lt;br /&gt;[#token()]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the numeric token's value]&lt;br /&gt;[#token($parameterName)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the named token's value]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Inserts token values into a tokenized format string where:&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$formatString&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;is the expression resulting in a string containing zero-based numeric (&lt;code&gt;{0}&lt;/code&gt;) or named (&lt;code&gt;{name}&lt;/code&gt;) tokens. The format string cannot mix numeric and named tokens.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Token values are defined using one or more&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;directives within the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#format&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;block. Each&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;can optionally identify a token name.&lt;/p&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{0}, {1}, and {2}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{a}, {b}, and {c}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;a&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;b&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;c&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="registerEndOfPageHtml"&gt;&lt;/a&gt;#registerEndOfPageHtml&lt;/h4&gt;
&lt;pre&gt;#registerEndOfPageHtml([key])&lt;br /&gt;&amp;nbsp; [script to render at the bottom of the completed HTML page]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Registers a block of HTML at the end of the completed HTML page where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is an optional variable, property, or literal string value identifying the unique key with which the contained markup should be registered.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is not supplied, the contained script will always be added to the bottom of the completed HTML page. If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is supplied, the first &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#registerEndOfPageHtml&lt;/span&gt; directive executed will have its contained script added to the bottom of the completed page.&lt;/p&gt;
&lt;h4&gt;&lt;a name="evaluate"&gt;&lt;/a&gt;#evaluate&lt;/h4&gt;
&lt;pre&gt;#evaluate($script)&lt;/pre&gt;
&lt;p&gt;Execute a string as a Velocity script where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$script&lt;/span&gt; is a variable, property, or literal string containing Velocity script.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="stop"&gt;&lt;/a&gt;#stop&lt;/h4&gt;
&lt;pre&gt;#stop&lt;/pre&gt;
&lt;p&gt;Stops execution of the widget immediately.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#stop&lt;/span&gt; should only be used for debugging purposes. To hide a widget, use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$core_widget.Hide() &lt;/span&gt;instead.&lt;/p&gt;
&lt;h4&gt;&lt;a id="T_931095879" name="T_931095879"&gt;&lt;/a&gt;##&lt;/h4&gt;
&lt;pre&gt;## [comment]&lt;/pre&gt;
&lt;p&gt;Identifies a comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is a single line of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a id="T_755172541" name="T_755172541"&gt;&lt;/a&gt;#*&lt;/h4&gt;
&lt;pre&gt;#* [comment lines] *#&lt;/pre&gt;
&lt;p&gt;Identifies a multi-line comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is one or more lines of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_with_Velocity" name="Widget_Extension_Usage_with_Velocity"&gt;&lt;/a&gt;Widget Extension Usage with Velocity&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to velocity script, implemented as a set of widget extensions automatically available in the context of an executed Velocity script. Additionally, custom extensions can also be accessed.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;p&gt;When a widget extension method accepts a dictionary of options, those options can be passed using the Velocity syntax&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;%{ Key1 = $value1, Key2 = $value2 }&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the entire dictionary is passed as a formatted string.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Retrieve the current blog. If there is none, hide the widget
#set ($currentBlog = false)&lt;br /&gt;#set ($currentBlog = $core_v2_blog.Current)
#if (!$curentBlog)
	$core_v2_widget.Hide()
#end

## Retrieve the 5 latest blog posts
#set ($blogPosts = $core_v2_blogPost.List(&amp;quot;%{ BlogId = $currentBlog.Id, PageSize = 5 }&amp;quot;))

#foreach ($blogPost in $blogPosts)
#beforeall
	&amp;lt;ul&amp;gt;
#each
		&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;$core_v2_encoding.HtmlAttributeEncode($blogPost.Url)&amp;quot;&amp;gt;$blogPost.Title&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
#afterall
	&amp;lt;/ul&amp;gt;
#nodata
	&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;
#end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3 id="getting_the_current_foreach_index"&gt;&lt;a name="Getting_the_current_foreach_index"&gt;&lt;/a&gt;Getting the current Foreach Index&lt;/h3&gt;
&lt;p&gt;If you want to track the current index you will need to store the index as a local variable.&amp;nbsp; Here is an example of how you can do this.&lt;/p&gt;
&lt;pre&gt;#set($index = 0)
#foreach($tag in $core_v2_tags.Current)
  #each
	 #set($index = $index + 1)
#end
&lt;/pre&gt;
&lt;h3 id="concatenating_strings"&gt;Concatenating strings&lt;a name="Gotcha_NVelocity_Macros_with_Bodies"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="color:#444444;font-weight:normal;"&gt;Oftentimes you will need to combine two or more strings and pass the result as a parameter to a method, to do this, place the variables within double quotes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;#set($newVal = &amp;quot;$val1$val2&amp;quot;)&lt;/pre&gt;
&lt;h3 id="adding_a_variable_to_the_end_of_a_url_before_a_period"&gt;&lt;a name="Adding_a_variable_to_the_end_of_a_URL_before_a_period"&gt;&lt;/a&gt;Adding a variable to the end of a URL before a period&lt;/h3&gt;
&lt;p&gt;You may need to pass a Velocity variable as part of a URL, and you may need to pass it at the end of the URL before a period.&amp;nbsp; For example, if you are creating a URL for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;api.ashx/v2/groups/$groupId/members/users/$userId.json&lt;/span&gt; where &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; is a local Velocity variable, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; will not be formatted correctly because it is looking for a property named json on &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt;.&amp;nbsp; To get around this, you can use the strict formatting option for Velocity variables, like the following&lt;/p&gt;
&lt;pre&gt;api.ashx/v2/groups/$groupId/members/users/${userId}.json&lt;/pre&gt;
&lt;h3 id="gotcha_cannot_set_a_null_value"&gt;&lt;a name="Gotcha_Cannot_set_a_null_value"&gt;&lt;/a&gt;Working with null values&lt;/h3&gt;
&lt;p&gt;When Velocity evaluates&lt;/p&gt;
&lt;pre&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;if&amp;nbsp;$someExtension.someMethod()&amp;nbsp;evaluates to&amp;nbsp;null,&amp;nbsp;$variable&amp;nbsp;will not be changed. It will still have its previous value. To reuse the&amp;nbsp;$variable&amp;nbsp;variable (in a&amp;nbsp;#foreach, for example), instead use:&lt;/p&gt;
&lt;pre&gt;#set ($variable = false)&lt;br /&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;This is how links widgets must be implemented.&amp;nbsp;&lt;/p&gt;
&lt;h3 id="programmatically_modifyingbuilding_dictionary_options"&gt;&lt;a name="Programmatically_Modifying_Building_IDictionary_Options"&gt;&lt;/a&gt;Programmatically modifying/building dictionary options&lt;/h3&gt;
&lt;p&gt;It is already possible to do calls like this&lt;/p&gt;
&lt;pre&gt;$core_v2_foo.Bar(42, &amp;quot;%{ key1 = &amp;quot;value&amp;quot;, key2 = &amp;quot;value2&amp;quot; }&lt;/pre&gt;
&lt;p&gt;Sometimes it is necessary to programmatically build the options dictionary for looping or logical reasons. This can be done as follows:&lt;/p&gt;
&lt;pre&gt;#set ($options = &amp;quot;%{}&amp;quot;)
$options.Add(newKey, &amp;quot;newValue&amp;quot;)&lt;/pre&gt;
&lt;p&gt;Try&amp;nbsp;&lt;code&gt;$core_help.Dump()&lt;/code&gt;ing&amp;nbsp;&lt;code&gt;$options&lt;/code&gt;&amp;nbsp;to see the full set of methods available for operating on the dictionary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Using Velocity</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity/revision/5</link><pubDate>Fri, 21 Jun 2019 19:53:42 GMT</pubDate><guid isPermaLink="false">3d8b9043-6f89-469f-a437-4e17fba4ac00</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity#comments</comments><description>Revision 5 posted to Developer Training by Ben Tiedt on 06/21/2019 19:53:42&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;Widget content is implemented using a version of the Velocity templating language.&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_the_Velocity_templating_language" name="When_should_I_use_the_Velocity_templating_language"&gt;&lt;/a&gt;When should I use the Velocity templating language?&lt;/h2&gt;
&lt;p&gt;Velocity is one of the two languages used to implement server side [[Scripting|scripts]] used by scripted customizations. Velocity is a templating language best suited to conditional rendering of content to form a string (for example, the HTML rendering of a [[Widgets|widget]]) whereas [[Using Server-side Javascript|Server-side Javascript]] is better suited for data processing. Velocity has full access to the Widget/Scripting API to interact with the Verint Community platform.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Velocity_Language_Syntax" name="Velocity_Language_Syntax"&gt;&lt;/a&gt;Velocity Language Syntax&lt;/h2&gt;
&lt;h3&gt;&lt;a name="Variables_Properties_and_Methods"&gt;&lt;/a&gt;Variables, properties, and methods&lt;/h3&gt;
&lt;h4 id="variables_and_extensions"&gt;&lt;a name="Variables_and_Extensions"&gt;&lt;/a&gt;Variables and extensions&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Variable and extension names must start with a dollar sign and an alphabetic letter.&lt;/p&gt;
&lt;p&gt;When the value of the variable is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$variable&lt;/span&gt; will render the name of the variable and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!variable&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${variable}&lt;/span&gt; is the formal notation for variables and distinguishes variable references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${variable}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Properties"&gt;&lt;/a&gt;Properties&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference properties on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the value of the property is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Property&lt;/span&gt; will render the name of the extension and property and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Property&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Property}&lt;/span&gt; is the formal notation for properties and distinguishes property references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Property}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Methods"&gt;&lt;/a&gt;Methods&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*([optional_parameter_list])[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference methods on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the return value of the method is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Method()&lt;/span&gt; will render the name of the extension and method and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Method()&lt;/span&gt; will render nothing. If the return value is void, nothing will be rendered.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Method()}&lt;/span&gt; is the formal notation for methods and distinguishes method references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Method()}this&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a name="Directives"&gt;&lt;/a&gt;Directives&lt;/h3&gt;
&lt;h4 id="set"&gt;&lt;a name="set"&gt;&lt;/a&gt;#set&lt;/h4&gt;
&lt;pre&gt;#set($reference = [argument])&lt;/pre&gt;
&lt;p&gt;Assigns a value to a variable or property where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$reference&lt;/span&gt; is a variable or property reference.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a method, variable, or property reference&lt;/li&gt;
&lt;li&gt;a literal boolean (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;true &lt;/span&gt;or &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;false&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal number (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[0-9]*.[0-9]*&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal string in single or double quotes&lt;/li&gt;
&lt;li&gt;an array definition (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[$item1, $item2, $item3,... $itemN]&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a mathematic expression:&lt;/li&gt;
&lt;li&gt;Addition: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n + 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Subtraction: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n - 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Multiplication: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n * $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Division: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n / $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Modulus:&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; #set($n = $n % $x)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument] &lt;/span&gt;is a literal string, strings in double quotes will be parsed whereas strings in single quotes will not be parsed.&lt;/p&gt;
&lt;div class="documentation-member"&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="store" name="store"&gt;&lt;/a&gt;#store&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#store($reference)&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the value assigned to the variable]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Assigns the result of executing a block of script to a variable where&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$reference&lt;/span&gt;&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a variable reference.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="code"&gt;#store($result)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;a href=&amp;quot;$user.ProfileUrl&amp;quot;&amp;gt;$user.DisplayName&amp;lt;/a&amp;gt;&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="if"&gt;&lt;/a&gt;#if&lt;/h4&gt;
&lt;pre&gt;#if([condition])&lt;br /&gt;&amp;nbsp; [script to execute when if condition is true]&lt;br /&gt;[&lt;br /&gt;#elseif([condition])&lt;br /&gt;&amp;nbsp; [script to execute when elseif condition is true]&lt;br /&gt;]*&lt;br /&gt;[&lt;br /&gt;#else&lt;br /&gt;&amp;nbsp; [script to execute if no conditions are true]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Conditionally renders templates where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[condition]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a Boolean expression:
&lt;ul&gt;
&lt;li&gt;Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x == $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt; $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt; 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;a non-Boolean variable, property, method, or literal reference (true if not null, otherwise false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="margin:0;padding:0;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="foreach"&gt;&lt;/a&gt;#foreach&lt;/h4&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;[#each]&lt;br /&gt;&amp;nbsp; [script to execute for each item]&lt;br /&gt;[&lt;br /&gt;#before&lt;br /&gt;&amp;nbsp; [script to execute before each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#after&lt;br /&gt;&amp;nbsp; [script to execute after each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#between&lt;br /&gt;&amp;nbsp; [script to execute between each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#odd&lt;br /&gt;&amp;nbsp; [script to execute for every other item, including the first]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#even&lt;br /&gt;&amp;nbsp; [script to execute for every other item, starting with the second]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#nodata&lt;br /&gt;&amp;nbsp; [script to execute if $items is null or empty]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#beforeall&lt;br /&gt;&amp;nbsp; [script to execute before all items, if there are items]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#afterall&lt;br /&gt;&amp;nbsp; [script to execute after all items, if there are items]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Renders templates for each item within a collection of items where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$item&lt;/span&gt; is the variable containing each item in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; collection when executing &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt;, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#odd&lt;/span&gt;, and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#even&lt;/span&gt; scripts.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; is a variable, property, or method resulting in a collection of items.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...] &lt;/span&gt;is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt; is the default template, so,&lt;/p&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;is equivalent to&lt;/p&gt;
&lt;pre&gt;#foreach ($item in $items)&lt;br /&gt;#each&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="format" name="format"&gt;&lt;/a&gt;#format&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#format($formatString)&lt;br /&gt;[#token()]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the numeric token's value]&lt;br /&gt;[#token($parameterName)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the named token's value]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Inserts token values into a tokenized format string where:&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$formatString&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;is the expression resulting in a string containing zero-based numeric (&lt;code&gt;{0}&lt;/code&gt;) or named (&lt;code&gt;{name}&lt;/code&gt;) tokens. The format string cannot mix numeric and named tokens.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Token values are defined using one or more&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;directives within the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#format&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;block. Each&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;can optionally identify a token name.&lt;/p&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{0}, {1}, and {2}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{a}, {b}, and {c}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;a&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;b&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;c&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="registerEndOfPageHtml"&gt;&lt;/a&gt;#registerEndOfPageHtml&lt;/h4&gt;
&lt;pre&gt;#registerEndOfPageHtml([key])&lt;br /&gt;&amp;nbsp; [script to render at the bottom of the completed HTML page]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Registers a block of HTML at the end of the completed HTML page where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is an optional variable, property, or literal string value identifying the unique key with which the contained markup should be registered.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is not supplied, the contained script will always be added to the bottom of the completed HTML page. If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is supplied, the first &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#registerEndOfPageHtml&lt;/span&gt; directive executed will have its contained script added to the bottom of the completed page.&lt;/p&gt;
&lt;h4&gt;&lt;a name="evaluate"&gt;&lt;/a&gt;#evaluate&lt;/h4&gt;
&lt;pre&gt;#evaluate($script)&lt;/pre&gt;
&lt;p&gt;Execute a string as a Velocity script where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$script&lt;/span&gt; is a variable, property, or literal string containing Velocity script.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="stop"&gt;&lt;/a&gt;#stop&lt;/h4&gt;
&lt;pre&gt;#stop&lt;/pre&gt;
&lt;p&gt;Stops execution of the widget immediately.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#stop&lt;/span&gt; should only be used for debugging purposes. To hide a widget, use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$core_widget.Hide() &lt;/span&gt;instead.&lt;/p&gt;
&lt;h4&gt;&lt;a id="T_931095879" name="T_931095879"&gt;&lt;/a&gt;##&lt;/h4&gt;
&lt;pre&gt;## [comment]&lt;/pre&gt;
&lt;p&gt;Identifies a comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is a single line of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a id="T_755172541" name="T_755172541"&gt;&lt;/a&gt;#*&lt;/h4&gt;
&lt;pre&gt;#* [comment lines] *#&lt;/pre&gt;
&lt;p&gt;Identifies a multi-line comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is one or more lines of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_with_Velocity" name="Widget_Extension_Usage_with_Velocity"&gt;&lt;/a&gt;Widget Extension Usage with Velocity&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to velocity script, implemented as a set of widget extensions automatically available in the context of an executed Velocity script. Additionally, custom extensions can also be accessed.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;p&gt;When a widget extension method accepts a dictionary of options, those options can be passed using the Velocity syntax&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;%{ Key1 = $value1, Key2 = $value2 }&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the entire dictionary is passed as a formatted string.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Retrieve the current blog. If there is none, hide the widget
#set ($currentBlog = $core_v2_blog.Current.Id)
#if (!$curentBlog)
	$core_v2_widget.Hide()
#end

## Retrieve the 5 latest blog posts
#set ($blogPosts = $core_v2_blogPost.List(&amp;quot;%{ BlogId = $currentBlog.Id, PageSize = 5 }&amp;quot;))

#foreach ($blogPost in $blogPosts)
#beforeall
	&amp;lt;ul&amp;gt;
#each
		&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;$core_v2_encoding.HtmlAttributeEncode($blogPost.Url)&amp;quot;&amp;gt;$blogPost.Title&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
#afterall
	&amp;lt;/ul&amp;gt;
#nodata
	&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;
#end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3 id="getting_the_current_foreach_index"&gt;&lt;a name="Getting_the_current_foreach_index"&gt;&lt;/a&gt;Getting the current Foreach Index&lt;/h3&gt;
&lt;p&gt;If you want to track the current index you will need to store the index as a local variable.&amp;nbsp; Here is an example of how you can do this.&lt;/p&gt;
&lt;pre&gt;#set($index = 0)
#foreach($tag in $core_v2_tags.Current)
  #each
	 #set($index = $index + 1)
#end
&lt;/pre&gt;
&lt;h3 id="concatenating_strings"&gt;Concatenating strings&lt;a name="Gotcha_NVelocity_Macros_with_Bodies"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="color:#444444;font-weight:normal;"&gt;Oftentimes you will need to combine two or more strings and pass the result as a parameter to a method, to do this, place the variables within double quotes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;#set($newVal = &amp;quot;$val1$val2&amp;quot;)&lt;/pre&gt;
&lt;h3 id="adding_a_variable_to_the_end_of_a_url_before_a_period"&gt;&lt;a name="Adding_a_variable_to_the_end_of_a_URL_before_a_period"&gt;&lt;/a&gt;Adding a variable to the end of a URL before a period&lt;/h3&gt;
&lt;p&gt;You may need to pass a Velocity variable as part of a URL, and you may need to pass it at the end of the URL before a period.&amp;nbsp; For example, if you are creating a URL for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;api.ashx/v2/groups/$groupId/members/users/$userId.json&lt;/span&gt; where &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; is a local Velocity variable, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; will not be formatted correctly because it is looking for a property named json on &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt;.&amp;nbsp; To get around this, you can use the strict formatting option for Velocity variables, like the following&lt;/p&gt;
&lt;pre&gt;api.ashx/v2/groups/$groupId/members/users/${userId}.json&lt;/pre&gt;
&lt;h3 id="gotcha_cannot_set_a_null_value"&gt;&lt;a name="Gotcha_Cannot_set_a_null_value"&gt;&lt;/a&gt;Working with null values&lt;/h3&gt;
&lt;p&gt;When Velocity evaluates&lt;/p&gt;
&lt;pre&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;if&amp;nbsp;$someExtension.someMethod()&amp;nbsp;evaluates to&amp;nbsp;null,&amp;nbsp;$variable&amp;nbsp;will not be changed. It will still have its previous value. To reuse the&amp;nbsp;$variable&amp;nbsp;variable (in a&amp;nbsp;#foreach, for example), instead use:&lt;/p&gt;
&lt;pre&gt;#set ($variable = false)&lt;br /&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;This is how links widgets must be implemented.&amp;nbsp;&lt;/p&gt;
&lt;h3 id="programmatically_modifyingbuilding_dictionary_options"&gt;&lt;a name="Programmatically_Modifying_Building_IDictionary_Options"&gt;&lt;/a&gt;Programmatically modifying/building dictionary options&lt;/h3&gt;
&lt;p&gt;It is already possible to do calls like this&lt;/p&gt;
&lt;pre&gt;$core_v2_foo.Bar(42, &amp;quot;%{ key1 = &amp;quot;value&amp;quot;, key2 = &amp;quot;value2&amp;quot; }&lt;/pre&gt;
&lt;p&gt;Sometimes it is necessary to programmatically build the options dictionary for looping or logical reasons. This can be done as follows:&lt;/p&gt;
&lt;pre&gt;#set ($options = &amp;quot;%{}&amp;quot;)
$options.Add(newKey, &amp;quot;newValue&amp;quot;)&lt;/pre&gt;
&lt;p&gt;Try&amp;nbsp;&lt;code&gt;$core_help.Dump()&lt;/code&gt;ing&amp;nbsp;&lt;code&gt;$options&lt;/code&gt;&amp;nbsp;to see the full set of methods available for operating on the dictionary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Using Velocity</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity/revision/4</link><pubDate>Fri, 21 Jun 2019 19:45:37 GMT</pubDate><guid isPermaLink="false">3d8b9043-6f89-469f-a437-4e17fba4ac00</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity#comments</comments><description>Revision 4 posted to Developer Training by Ben Tiedt on 06/21/2019 19:45:37&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;Widget content is implemented using a version of the Velocity templating language.&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_the_Velocity_templating_language" name="When_should_I_use_the_Velocity_templating_language"&gt;&lt;/a&gt;When should I use the Velocity templating language?&lt;/h2&gt;
&lt;p&gt;Velocity is one of the two languages used to implement server side [[Scripting|scripts]] used by scripted customizations. Velocity is a templating language best suited to conditional rendering of content to form a string (for example, the HTML rendering of a [[Widgets|widget]]). Velocity has full access to the Widget/Scripting API to interact with the Verint Community platform.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Velocity_Language_Syntax" name="Velocity_Language_Syntax"&gt;&lt;/a&gt;Velocity Language Syntax&lt;/h2&gt;
&lt;h3&gt;&lt;a name="Variables_Properties_and_Methods"&gt;&lt;/a&gt;Variables, properties, and methods&lt;/h3&gt;
&lt;h4 id="variables_and_extensions"&gt;&lt;a name="Variables_and_Extensions"&gt;&lt;/a&gt;Variables and extensions&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Variable and extension names must start with a dollar sign and an alphabetic letter.&lt;/p&gt;
&lt;p&gt;When the value of the variable is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$variable&lt;/span&gt; will render the name of the variable and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!variable&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${variable}&lt;/span&gt; is the formal notation for variables and distinguishes variable references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${variable}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Properties"&gt;&lt;/a&gt;Properties&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference properties on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the value of the property is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Property&lt;/span&gt; will render the name of the extension and property and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Property&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Property}&lt;/span&gt; is the formal notation for properties and distinguishes property references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Property}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Methods"&gt;&lt;/a&gt;Methods&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*([optional_parameter_list])[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference methods on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the return value of the method is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Method()&lt;/span&gt; will render the name of the extension and method and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Method()&lt;/span&gt; will render nothing. If the return value is void, nothing will be rendered.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Method()}&lt;/span&gt; is the formal notation for methods and distinguishes method references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Method()}this&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a name="Directives"&gt;&lt;/a&gt;Directives&lt;/h3&gt;
&lt;h4 id="set"&gt;&lt;a name="set"&gt;&lt;/a&gt;#set&lt;/h4&gt;
&lt;pre&gt;#set($reference = [argument])&lt;/pre&gt;
&lt;p&gt;Assigns a value to a variable or property where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$reference&lt;/span&gt; is a variable or property reference.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a method, variable, or property reference&lt;/li&gt;
&lt;li&gt;a literal boolean (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;true &lt;/span&gt;or &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;false&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal number (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[0-9]*.[0-9]*&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal string in single or double quotes&lt;/li&gt;
&lt;li&gt;an array definition (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[$item1, $item2, $item3,... $itemN]&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a mathematic expression:&lt;/li&gt;
&lt;li&gt;Addition: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n + 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Subtraction: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n - 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Multiplication: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n * $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Division: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n / $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Modulus:&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; #set($n = $n % $x)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument] &lt;/span&gt;is a literal string, strings in double quotes will be parsed whereas strings in single quotes will not be parsed.&lt;/p&gt;
&lt;div class="documentation-member"&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="store" name="store"&gt;&lt;/a&gt;#store&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#store($reference)&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the value assigned to the variable]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Assigns the result of executing a block of script to a variable where&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$reference&lt;/span&gt;&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a variable reference.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="code"&gt;#store($result)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;a href=&amp;quot;$user.ProfileUrl&amp;quot;&amp;gt;$user.DisplayName&amp;lt;/a&amp;gt;&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="if"&gt;&lt;/a&gt;#if&lt;/h4&gt;
&lt;pre&gt;#if([condition])&lt;br /&gt;&amp;nbsp; [script to execute when if condition is true]&lt;br /&gt;[&lt;br /&gt;#elseif([condition])&lt;br /&gt;&amp;nbsp; [script to execute when elseif condition is true]&lt;br /&gt;]*&lt;br /&gt;[&lt;br /&gt;#else&lt;br /&gt;&amp;nbsp; [script to execute if no conditions are true]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Conditionally renders templates where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[condition]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a Boolean expression:
&lt;ul&gt;
&lt;li&gt;Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x == $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt; $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt; 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;a non-Boolean variable, property, method, or literal reference (true if not null, otherwise false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="margin:0;padding:0;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="foreach"&gt;&lt;/a&gt;#foreach&lt;/h4&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;[#each]&lt;br /&gt;&amp;nbsp; [script to execute for each item]&lt;br /&gt;[&lt;br /&gt;#before&lt;br /&gt;&amp;nbsp; [script to execute before each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#after&lt;br /&gt;&amp;nbsp; [script to execute after each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#between&lt;br /&gt;&amp;nbsp; [script to execute between each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#odd&lt;br /&gt;&amp;nbsp; [script to execute for every other item, including the first]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#even&lt;br /&gt;&amp;nbsp; [script to execute for every other item, starting with the second]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#nodata&lt;br /&gt;&amp;nbsp; [script to execute if $items is null or empty]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#beforeall&lt;br /&gt;&amp;nbsp; [script to execute before all items, if there are items]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#afterall&lt;br /&gt;&amp;nbsp; [script to execute after all items, if there are items]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Renders templates for each item within a collection of items where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$item&lt;/span&gt; is the variable containing each item in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; collection when executing &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt;, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#odd&lt;/span&gt;, and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#even&lt;/span&gt; scripts.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; is a variable, property, or method resulting in a collection of items.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...] &lt;/span&gt;is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt; is the default template, so,&lt;/p&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;is equivalent to&lt;/p&gt;
&lt;pre&gt;#foreach ($item in $items)&lt;br /&gt;#each&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="format" name="format"&gt;&lt;/a&gt;#format&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#format($formatString)&lt;br /&gt;[#token()]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the numeric token's value]&lt;br /&gt;[#token($parameterName)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the named token's value]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Inserts token values into a tokenized format string where:&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$formatString&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;is the expression resulting in a string containing zero-based numeric (&lt;code&gt;{0}&lt;/code&gt;) or named (&lt;code&gt;{name}&lt;/code&gt;) tokens. The format string cannot mix numeric and named tokens.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Token values are defined using one or more&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;directives within the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#format&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;block. Each&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;can optionally identify a token name.&lt;/p&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{0}, {1}, and {2}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{a}, {b}, and {c}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;a&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;b&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;c&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="registerEndOfPageHtml"&gt;&lt;/a&gt;#registerEndOfPageHtml&lt;/h4&gt;
&lt;pre&gt;#registerEndOfPageHtml([key])&lt;br /&gt;&amp;nbsp; [script to render at the bottom of the completed HTML page]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Registers a block of HTML at the end of the completed HTML page where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is an optional variable, property, or literal string value identifying the unique key with which the contained markup should be registered.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is not supplied, the contained script will always be added to the bottom of the completed HTML page. If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is supplied, the first &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#registerEndOfPageHtml&lt;/span&gt; directive executed will have its contained script added to the bottom of the completed page.&lt;/p&gt;
&lt;h4&gt;&lt;a name="evaluate"&gt;&lt;/a&gt;#evaluate&lt;/h4&gt;
&lt;pre&gt;#evaluate($script)&lt;/pre&gt;
&lt;p&gt;Execute a string as a Velocity script where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$script&lt;/span&gt; is a variable, property, or literal string containing Velocity script.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="stop"&gt;&lt;/a&gt;#stop&lt;/h4&gt;
&lt;pre&gt;#stop&lt;/pre&gt;
&lt;p&gt;Stops execution of the widget immediately.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#stop&lt;/span&gt; should only be used for debugging purposes. To hide a widget, use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$core_widget.Hide() &lt;/span&gt;instead.&lt;/p&gt;
&lt;h4&gt;&lt;a id="T_931095879" name="T_931095879"&gt;&lt;/a&gt;##&lt;/h4&gt;
&lt;pre&gt;## [comment]&lt;/pre&gt;
&lt;p&gt;Identifies a comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is a single line of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a id="T_755172541" name="T_755172541"&gt;&lt;/a&gt;#*&lt;/h4&gt;
&lt;pre&gt;#* [comment lines] *#&lt;/pre&gt;
&lt;p&gt;Identifies a multi-line comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is one or more lines of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_with_Velocity" name="Widget_Extension_Usage_with_Velocity"&gt;&lt;/a&gt;Widget Extension Usage with Velocity&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to velocity script, implemented as a set of widget extensions automatically available in the context of an executed Velocity script. Additionally, custom extensions can also be accessed.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;p&gt;When a widget extension method accepts a dictionary of options, those options can be passed using the Velocity syntax&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;%{ Key1 = $value1, Key2 = $value2 }&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the entire dictionary is passed as a formatted string.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Retrieve the current blog. If there is none, hide the widget
#set ($currentBlog = $core_v2_blog.Current.Id)
#if (!$curentBlog)
	$core_v2_widget.Hide()
#end

## Retrieve the 5 latest blog posts
#set ($blogPosts = $core_v2_blogPost.List(&amp;quot;%{ BlogId = $currentBlog.Id, PageSize = 5 }&amp;quot;))

#foreach ($blogPost in $blogPosts)
#beforeall
	&amp;lt;ul&amp;gt;
#each
		&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;$core_v2_encoding.HtmlAttributeEncode($blogPost.Url)&amp;quot;&amp;gt;$blogPost.Title&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
#afterall
	&amp;lt;/ul&amp;gt;
#nodata
	&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;
#end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3 id="getting_the_current_foreach_index"&gt;&lt;a name="Getting_the_current_foreach_index"&gt;&lt;/a&gt;Getting the current Foreach Index&lt;/h3&gt;
&lt;p&gt;If you want to track the current index you will need to store the index as a local variable.&amp;nbsp; Here is an example of how you can do this.&lt;/p&gt;
&lt;pre&gt;#set($index = 0)
#foreach($tag in $core_v2_tags.Current)
  #each
	 #set($index = $index + 1)
#end
&lt;/pre&gt;
&lt;h3 id="concatenating_strings"&gt;Concatenating strings&lt;a name="Gotcha_NVelocity_Macros_with_Bodies"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="color:#444444;font-weight:normal;"&gt;Oftentimes you will need to combine two or more strings and pass the result as a parameter to a method, to do this, place the variables within double quotes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;#set($newVal = &amp;quot;$val1$val2&amp;quot;)&lt;/pre&gt;
&lt;h3 id="adding_a_variable_to_the_end_of_a_url_before_a_period"&gt;&lt;a name="Adding_a_variable_to_the_end_of_a_URL_before_a_period"&gt;&lt;/a&gt;Adding a variable to the end of a URL before a period&lt;/h3&gt;
&lt;p&gt;You may need to pass a Velocity variable as part of a URL, and you may need to pass it at the end of the URL before a period.&amp;nbsp; For example, if you are creating a URL for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;api.ashx/v2/groups/$groupId/members/users/$userId.json&lt;/span&gt; where &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; is a local Velocity variable, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; will not be formatted correctly because it is looking for a property named json on &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt;.&amp;nbsp; To get around this, you can use the strict formatting option for Velocity variables, like the following&lt;/p&gt;
&lt;pre&gt;api.ashx/v2/groups/$groupId/members/users/${userId}.json&lt;/pre&gt;
&lt;h3 id="gotcha_cannot_set_a_null_value"&gt;&lt;a name="Gotcha_Cannot_set_a_null_value"&gt;&lt;/a&gt;Working with null values&lt;/h3&gt;
&lt;p&gt;When Velocity evaluates&lt;/p&gt;
&lt;pre&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;if&amp;nbsp;$someExtension.someMethod()&amp;nbsp;evaluates to&amp;nbsp;null,&amp;nbsp;$variable&amp;nbsp;will not be changed. It will still have its previous value. To reuse the&amp;nbsp;$variable&amp;nbsp;variable (in a&amp;nbsp;#foreach, for example), instead use:&lt;/p&gt;
&lt;pre&gt;#set ($variable = false)&lt;br /&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;This is how links widgets must be implemented.&amp;nbsp;&lt;/p&gt;
&lt;h3 id="programmatically_modifyingbuilding_dictionary_options"&gt;&lt;a name="Programmatically_Modifying_Building_IDictionary_Options"&gt;&lt;/a&gt;Programmatically modifying/building dictionary options&lt;/h3&gt;
&lt;p&gt;It is already possible to do calls like this&lt;/p&gt;
&lt;pre&gt;$core_v2_foo.Bar(42, &amp;quot;%{ key1 = &amp;quot;value&amp;quot;, key2 = &amp;quot;value2&amp;quot; }&lt;/pre&gt;
&lt;p&gt;Sometimes it is necessary to programmatically build the options dictionary for looping or logical reasons. This can be done as follows:&lt;/p&gt;
&lt;pre&gt;#set ($options = &amp;quot;%{}&amp;quot;)
$options.Add(newKey, &amp;quot;newValue&amp;quot;)&lt;/pre&gt;
&lt;p&gt;Try&amp;nbsp;&lt;code&gt;$core_help.Dump()&lt;/code&gt;ing&amp;nbsp;&lt;code&gt;$options&lt;/code&gt;&amp;nbsp;to see the full set of methods available for operating on the dictionary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Using Velocity</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity/revision/3</link><pubDate>Fri, 21 Jun 2019 19:39:42 GMT</pubDate><guid isPermaLink="false">3d8b9043-6f89-469f-a437-4e17fba4ac00</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity#comments</comments><description>Revision 3 posted to Developer Training by Ben Tiedt on 06/21/2019 19:39:42&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;Widget content is implemented using a version of the Velocity templating language.&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_the_Velocity_templating_language" name="When_should_I_use_the_Velocity_templating_language"&gt;&lt;/a&gt;When should I use the Velocity templating language?&lt;/h2&gt;
&lt;p&gt;Velocity is the server side templating language used by widgets. In addition to providing server-side templating, Velocity is used to perform server side requests against the [[api-documentation:Widget Extensions|Widget Extension Platform API]] including custom [[Widget Extensions]].&lt;/p&gt;
&lt;h2&gt;&lt;a id="Velocity_Language_Syntax" name="Velocity_Language_Syntax"&gt;&lt;/a&gt;Velocity Language Syntax&lt;/h2&gt;
&lt;h3&gt;&lt;a name="Variables_Properties_and_Methods"&gt;&lt;/a&gt;Variables, properties, and methods&lt;/h3&gt;
&lt;h4 id="variables_and_extensions"&gt;&lt;a name="Variables_and_Extensions"&gt;&lt;/a&gt;Variables and extensions&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Variable and extension names must start with a dollar sign and an alphabetic letter.&lt;/p&gt;
&lt;p&gt;When the value of the variable is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$variable&lt;/span&gt; will render the name of the variable and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!variable&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${variable}&lt;/span&gt; is the formal notation for variables and distinguishes variable references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${variable}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Properties"&gt;&lt;/a&gt;Properties&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference properties on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the value of the property is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Property&lt;/span&gt; will render the name of the extension and property and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Property&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Property}&lt;/span&gt; is the formal notation for properties and distinguishes property references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Property}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Methods"&gt;&lt;/a&gt;Methods&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*([optional_parameter_list])[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference methods on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the return value of the method is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Method()&lt;/span&gt; will render the name of the extension and method and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Method()&lt;/span&gt; will render nothing. If the return value is void, nothing will be rendered.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Method()}&lt;/span&gt; is the formal notation for methods and distinguishes method references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Method()}this&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a name="Directives"&gt;&lt;/a&gt;Directives&lt;/h3&gt;
&lt;h4 id="set"&gt;&lt;a name="set"&gt;&lt;/a&gt;#set&lt;/h4&gt;
&lt;pre&gt;#set($reference = [argument])&lt;/pre&gt;
&lt;p&gt;Assigns a value to a variable or property where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$reference&lt;/span&gt; is a variable or property reference.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a method, variable, or property reference&lt;/li&gt;
&lt;li&gt;a literal boolean (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;true &lt;/span&gt;or &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;false&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal number (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[0-9]*.[0-9]*&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal string in single or double quotes&lt;/li&gt;
&lt;li&gt;an array definition (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[$item1, $item2, $item3,... $itemN]&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a mathematic expression:&lt;/li&gt;
&lt;li&gt;Addition: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n + 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Subtraction: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n - 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Multiplication: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n * $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Division: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n / $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Modulus:&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; #set($n = $n % $x)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument] &lt;/span&gt;is a literal string, strings in double quotes will be parsed whereas strings in single quotes will not be parsed.&lt;/p&gt;
&lt;div class="documentation-member"&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="store" name="store"&gt;&lt;/a&gt;#store&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#store($reference)&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the value assigned to the variable]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Assigns the result of executing a block of script to a variable where&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$reference&lt;/span&gt;&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is a variable reference.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="code"&gt;#store($result)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;a href=&amp;quot;$user.ProfileUrl&amp;quot;&amp;gt;$user.DisplayName&amp;lt;/a&amp;gt;&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="if"&gt;&lt;/a&gt;#if&lt;/h4&gt;
&lt;pre&gt;#if([condition])&lt;br /&gt;&amp;nbsp; [script to execute when if condition is true]&lt;br /&gt;[&lt;br /&gt;#elseif([condition])&lt;br /&gt;&amp;nbsp; [script to execute when elseif condition is true]&lt;br /&gt;]*&lt;br /&gt;[&lt;br /&gt;#else&lt;br /&gt;&amp;nbsp; [script to execute if no conditions are true]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Conditionally renders templates where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[condition]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a Boolean expression:
&lt;ul&gt;
&lt;li&gt;Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x == $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt; $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt; 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;a non-Boolean variable, property, method, or literal reference (true if not null, otherwise false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="margin:0;padding:0;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="foreach"&gt;&lt;/a&gt;#foreach&lt;/h4&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;[#each]&lt;br /&gt;&amp;nbsp; [script to execute for each item]&lt;br /&gt;[&lt;br /&gt;#before&lt;br /&gt;&amp;nbsp; [script to execute before each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#after&lt;br /&gt;&amp;nbsp; [script to execute after each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#between&lt;br /&gt;&amp;nbsp; [script to execute between each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#odd&lt;br /&gt;&amp;nbsp; [script to execute for every other item, including the first]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#even&lt;br /&gt;&amp;nbsp; [script to execute for every other item, starting with the second]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#nodata&lt;br /&gt;&amp;nbsp; [script to execute if $items is null or empty]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#beforeall&lt;br /&gt;&amp;nbsp; [script to execute before all items, if there are items]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#afterall&lt;br /&gt;&amp;nbsp; [script to execute after all items, if there are items]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Renders templates for each item within a collection of items where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$item&lt;/span&gt; is the variable containing each item in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; collection when executing &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt;, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#odd&lt;/span&gt;, and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#even&lt;/span&gt; scripts.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; is a variable, property, or method resulting in a collection of items.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...] &lt;/span&gt;is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt; is the default template, so,&lt;/p&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;is equivalent to&lt;/p&gt;
&lt;pre&gt;#foreach ($item in $items)&lt;br /&gt;#each&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;h4 class="member_heading"&gt;&lt;a id="format" name="format"&gt;&lt;/a&gt;#format&lt;/h4&gt;
&lt;div class="documentation-member-body"&gt;
&lt;div class="MethodOverloads"&gt;
&lt;div class="MethodOverload"&gt;
&lt;pre class="code"&gt;#format($formatString)&lt;br /&gt;[#token()]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the numeric token's value]&lt;br /&gt;[#token($parameterName)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;[script resulting in the named token's value]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Inserts token values into a tokenized format string where:&lt;/p&gt;
&lt;ul class="parameters"&gt;
&lt;li&gt;&lt;code&gt;&lt;span class="code"&gt;$formatString&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;is the expression resulting in a string containing zero-based numeric (&lt;code&gt;{0}&lt;/code&gt;) or named (&lt;code&gt;{name}&lt;/code&gt;) tokens. The format string cannot mix numeric and named tokens.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Token values are defined using one or more&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;directives within the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#format&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;block. Each&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;#token&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;can optionally identify a token name.&lt;/p&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{0}, {1}, and {2}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;pre class="code"&gt;#format(&amp;#39;{a}, {b}, and {c}&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;a&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;One&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;b&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Two&lt;br /&gt;&amp;nbsp;&amp;nbsp;#token(&amp;#39;c&amp;#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Three&lt;br /&gt;#end&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4&gt;&lt;a name="registerEndOfPageHtml"&gt;&lt;/a&gt;#registerEndOfPageHtml&lt;/h4&gt;
&lt;pre&gt;#registerEndOfPageHtml([key])&lt;br /&gt;&amp;nbsp; [script to render at the bottom of the completed HTML page]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Registers a block of HTML at the end of the completed HTML page where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is an optional variable, property, or literal string value identifying the unique key with which the contained markup should be registered.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is not supplied, the contained script will always be added to the bottom of the completed HTML page. If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is supplied, the first &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#registerEndOfPageHtml&lt;/span&gt; directive executed will have its contained script added to the bottom of the completed page.&lt;/p&gt;
&lt;h4&gt;&lt;a name="evaluate"&gt;&lt;/a&gt;#evaluate&lt;/h4&gt;
&lt;pre&gt;#evaluate($script)&lt;/pre&gt;
&lt;p&gt;Execute a string as a Velocity script where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$script&lt;/span&gt; is a variable, property, or literal string containing Velocity script.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="stop"&gt;&lt;/a&gt;#stop&lt;/h4&gt;
&lt;pre&gt;#stop&lt;/pre&gt;
&lt;p&gt;Stops execution of the widget immediately.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#stop&lt;/span&gt; should only be used for debugging purposes. To hide a widget, use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$core_widget.Hide() &lt;/span&gt;instead.&lt;/p&gt;
&lt;h4&gt;&lt;a id="T_931095879" name="T_931095879"&gt;&lt;/a&gt;##&lt;/h4&gt;
&lt;pre&gt;## [comment]&lt;/pre&gt;
&lt;p&gt;Identifies a comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is a single line of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a id="T_755172541" name="T_755172541"&gt;&lt;/a&gt;#*&lt;/h4&gt;
&lt;pre&gt;#* [comment lines] *#&lt;/pre&gt;
&lt;p&gt;Identifies a multi-line comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is one or more lines of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_with_Velocity" name="Widget_Extension_Usage_with_Velocity"&gt;&lt;/a&gt;Widget Extension Usage with Velocity&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to velocity script, implemented as a set of widget extensions automatically available in the context of an executed Velocity script. Additionally, custom extensions can also be accessed.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;p&gt;When a widget extension method accepts a dictionary of options, those options can be passed using the Velocity syntax&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;%{ Key1 = $value1, Key2 = $value2 }&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the entire dictionary is passed as a formatted string.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Retrieve the current blog. If there is none, hide the widget
#set ($currentBlog = $core_v2_blog.Current.Id)
#if (!$curentBlog)
	$core_v2_widget.Hide()
#end

## Retrieve the 5 latest blog posts
#set ($blogPosts = $core_v2_blogPost.List(&amp;quot;%{ BlogId = $currentBlog.Id, PageSize = 5 }&amp;quot;))

#foreach ($blogPost in $blogPosts)
#beforeall
	&amp;lt;ul&amp;gt;
#each
		&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;$core_v2_encoding.HtmlAttributeEncode($blogPost.Url)&amp;quot;&amp;gt;$blogPost.Title&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
#afterall
	&amp;lt;/ul&amp;gt;
#nodata
	&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;
#end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3 id="getting_the_current_foreach_index"&gt;&lt;a name="Getting_the_current_foreach_index"&gt;&lt;/a&gt;Getting the current Foreach Index&lt;/h3&gt;
&lt;p&gt;If you want to track the current index you will need to store the index as a local variable.&amp;nbsp; Here is an example of how you can do this.&lt;/p&gt;
&lt;pre&gt;#set($index = 0)
#foreach($tag in $core_v2_tags.Current)
  #each
	 #set($index = $index + 1)
#end
&lt;/pre&gt;
&lt;h3 id="concatenating_strings"&gt;Concatenating strings&lt;a name="Gotcha_NVelocity_Macros_with_Bodies"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="color:#444444;font-weight:normal;"&gt;Oftentimes you will need to combine two or more strings and pass the result as a parameter to a method, to do this, place the variables within double quotes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;#set($newVal = &amp;quot;$val1$val2&amp;quot;)&lt;/pre&gt;
&lt;h3 id="adding_a_variable_to_the_end_of_a_url_before_a_period"&gt;&lt;a name="Adding_a_variable_to_the_end_of_a_URL_before_a_period"&gt;&lt;/a&gt;Adding a variable to the end of a URL before a period&lt;/h3&gt;
&lt;p&gt;You may need to pass a Velocity variable as part of a URL, and you may need to pass it at the end of the URL before a period.&amp;nbsp; For example, if you are creating a URL for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;api.ashx/v2/groups/$groupId/members/users/$userId.json&lt;/span&gt; where &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; is a local Velocity variable, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; will not be formatted correctly because it is looking for a property named json on &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt;.&amp;nbsp; To get around this, you can use the strict formatting option for Velocity variables, like the following&lt;/p&gt;
&lt;pre&gt;api.ashx/v2/groups/$groupId/members/users/${userId}.json&lt;/pre&gt;
&lt;h3 id="gotcha_cannot_set_a_null_value"&gt;&lt;a name="Gotcha_Cannot_set_a_null_value"&gt;&lt;/a&gt;Working with null values&lt;/h3&gt;
&lt;p&gt;When Velocity evaluates&lt;/p&gt;
&lt;pre&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;if&amp;nbsp;$someExtension.someMethod()&amp;nbsp;evaluates to&amp;nbsp;null,&amp;nbsp;$variable&amp;nbsp;will not be changed. It will still have its previous value. To reuse the&amp;nbsp;$variable&amp;nbsp;variable (in a&amp;nbsp;#foreach, for example), instead use:&lt;/p&gt;
&lt;pre&gt;#set ($variable = false)&lt;br /&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;This is how links widgets must be implemented.&amp;nbsp;&lt;/p&gt;
&lt;h3 id="programmatically_modifyingbuilding_dictionary_options"&gt;&lt;a name="Programmatically_Modifying_Building_IDictionary_Options"&gt;&lt;/a&gt;Programmatically modifying/building dictionary options&lt;/h3&gt;
&lt;p&gt;It is already possible to do calls like this&lt;/p&gt;
&lt;pre&gt;$core_v2_foo.Bar(42, &amp;quot;%{ key1 = &amp;quot;value&amp;quot;, key2 = &amp;quot;value2&amp;quot; }&lt;/pre&gt;
&lt;p&gt;Sometimes it is necessary to programmatically build the options dictionary for looping or logical reasons. This can be done as follows:&lt;/p&gt;
&lt;pre&gt;#set ($options = &amp;quot;%{}&amp;quot;)
$options.Add(newKey, &amp;quot;newValue&amp;quot;)&lt;/pre&gt;
&lt;p&gt;Try&amp;nbsp;&lt;code&gt;$core_help.Dump()&lt;/code&gt;ing&amp;nbsp;&lt;code&gt;$options&lt;/code&gt;&amp;nbsp;to see the full set of methods available for operating on the dictionary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Using Velocity</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity/revision/2</link><pubDate>Fri, 21 Jun 2019 19:35:15 GMT</pubDate><guid isPermaLink="false">3d8b9043-6f89-469f-a437-4e17fba4ac00</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity#comments</comments><description>Revision 2 posted to Developer Training by Ben Tiedt on 06/21/2019 19:35:15&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;Widget content is implemented using a version of the Velocity templating language.&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_the_Velocity_templating_language" name="When_should_I_use_the_Velocity_templating_language"&gt;&lt;/a&gt;When should I use the Velocity templating language?&lt;/h2&gt;
&lt;p&gt;Velocity is the server side templating language used by widgets. In addition to providing server-side templating, Velocity is used to perform server side requests against the [[api-documentation:Widget Extensions|Widget Extension Platform API]] including custom [[Widget Extensions]].&lt;/p&gt;
&lt;h2&gt;&lt;a id="Velocity_Language_Syntax" name="Velocity_Language_Syntax"&gt;&lt;/a&gt;Velocity Language Syntax&lt;/h2&gt;
&lt;h3&gt;&lt;a name="Variables_Properties_and_Methods"&gt;&lt;/a&gt;Variables, properties, and methods&lt;/h3&gt;
&lt;h4 id="variables_and_extensions"&gt;&lt;a name="Variables_and_Extensions"&gt;&lt;/a&gt;Variables and extensions&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Variable and extension names must start with a dollar sign and an alphabetic letter.&lt;/p&gt;
&lt;p&gt;When the value of the variable is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$variable&lt;/span&gt; will render the name of the variable and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!variable&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${variable}&lt;/span&gt; is the formal notation for variables and distinguishes variable references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${variable}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Properties"&gt;&lt;/a&gt;Properties&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference properties on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the value of the property is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Property&lt;/span&gt; will render the name of the extension and property and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Property&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Property}&lt;/span&gt; is the formal notation for properties and distinguishes property references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Property}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Methods"&gt;&lt;/a&gt;Methods&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*([optional_parameter_list])[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference methods on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the return value of the method is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Method()&lt;/span&gt; will render the name of the extension and method and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Method()&lt;/span&gt; will render nothing. If the return value is void, nothing will be rendered.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Method()}&lt;/span&gt; is the formal notation for methods and distinguishes method references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Method()}this&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a name="Directives"&gt;&lt;/a&gt;Directives&lt;/h3&gt;
&lt;h4 id="set"&gt;&lt;a name="set"&gt;&lt;/a&gt;#set&lt;/h4&gt;
&lt;pre&gt;#set($reference = [argument])&lt;/pre&gt;
&lt;p&gt;Assigns a value to a variable or property where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$reference&lt;/span&gt; is a variable or property reference.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a method, variable, or property reference&lt;/li&gt;
&lt;li&gt;a literal boolean (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;true &lt;/span&gt;or &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;false&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal number (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[0-9]*.[0-9]*&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal string in single or double quotes&lt;/li&gt;
&lt;li&gt;an array definition (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[$item1, $item2, $item3,... $itemN]&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a mathematic expression:&lt;/li&gt;
&lt;li&gt;Addition: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n + 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Subtraction: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n - 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Multiplication: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n * $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Division: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n / $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Modulus:&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; #set($n = $n % $x)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument] &lt;/span&gt;is a literal string, strings in double quotes will be parsed whereas strings in single quotes will not be parsed.&lt;/p&gt;
&lt;h4&gt;&lt;a name="if"&gt;&lt;/a&gt;#if&lt;/h4&gt;
&lt;pre&gt;#if([condition])&lt;br /&gt;&amp;nbsp; [script to execute when if condition is true]&lt;br /&gt;[&lt;br /&gt;#elseif([condition])&lt;br /&gt;&amp;nbsp; [script to execute when elseif condition is true]&lt;br /&gt;]*&lt;br /&gt;[&lt;br /&gt;#else&lt;br /&gt;&amp;nbsp; [script to execute if no conditions are true]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Conditionally renders templates where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[condition]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a Boolean expression:
&lt;ul&gt;
&lt;li&gt;Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x == $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt; $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt; 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;a non-Boolean variable, property, method, or literal reference (true if not null, otherwise false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="margin:0;padding:0;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="foreach"&gt;&lt;/a&gt;#foreach&lt;/h4&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;[#each]&lt;br /&gt;&amp;nbsp; [script to execute for each item]&lt;br /&gt;[&lt;br /&gt;#before&lt;br /&gt;&amp;nbsp; [script to execute before each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#after&lt;br /&gt;&amp;nbsp; [script to execute after each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#between&lt;br /&gt;&amp;nbsp; [script to execute between each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#odd&lt;br /&gt;&amp;nbsp; [script to execute for every other item, including the first]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#even&lt;br /&gt;&amp;nbsp; [script to execute for every other item, starting with the second]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#nodata&lt;br /&gt;&amp;nbsp; [script to execute if $items is null or empty]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#beforeall&lt;br /&gt;&amp;nbsp; [script to execute before all items, if there are items]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#afterall&lt;br /&gt;&amp;nbsp; [script to execute after all items, if there are items]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Renders templates for each item within a collection of items where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$item&lt;/span&gt; is the variable containing each item in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; collection when executing &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt;, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#odd&lt;/span&gt;, and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#even&lt;/span&gt; scripts.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; is a variable, property, or method resulting in a collection of items.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...] &lt;/span&gt;is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt; is the default template, so,&lt;/p&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;is equivalent to&lt;/p&gt;
&lt;pre&gt;#foreach ($item in $items)&lt;br /&gt;#each&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;h4&gt;&lt;a name="registerEndOfPageHtml"&gt;&lt;/a&gt;#registerEndOfPageHtml&lt;/h4&gt;
&lt;pre&gt;#registerEndOfPageHtml([key])&lt;br /&gt;&amp;nbsp; [script to render at the bottom of the completed HTML page]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Registers a block of HTML at the end of the completed HTML page where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is an optional variable, property, or literal string value identifying the unique key with which the contained markup should be registered.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is not supplied, the contained script will always be added to the bottom of the completed HTML page. If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is supplied, the first &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#registerEndOfPageHtml&lt;/span&gt; directive executed will have its contained script added to the bottom of the completed page.&lt;/p&gt;
&lt;h4&gt;&lt;a name="evaluate"&gt;&lt;/a&gt;#evaluate&lt;/h4&gt;
&lt;pre&gt;#evaluate($script)&lt;/pre&gt;
&lt;p&gt;Execute a string as a Velocity script where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$script&lt;/span&gt; is a variable, property, or literal string containing Velocity script.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="stop"&gt;&lt;/a&gt;#stop&lt;/h4&gt;
&lt;pre&gt;#stop&lt;/pre&gt;
&lt;p&gt;Stops execution of the widget immediately.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#stop&lt;/span&gt; should only be used for debugging purposes. To hide a widget, use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$core_widget.Hide() &lt;/span&gt;instead.&lt;/p&gt;
&lt;h4&gt;&lt;a id="T_931095879" name="T_931095879"&gt;&lt;/a&gt;##&lt;/h4&gt;
&lt;pre&gt;## [comment]&lt;/pre&gt;
&lt;p&gt;Identifies a comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is a single line of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a id="T_755172541" name="T_755172541"&gt;&lt;/a&gt;#*&lt;/h4&gt;
&lt;pre&gt;#* [comment lines] *#&lt;/pre&gt;
&lt;p&gt;Identifies a multi-line comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is one or more lines of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_with_Velocity" name="Widget_Extension_Usage_with_Velocity"&gt;&lt;/a&gt;Widget Extension Usage with Velocity&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to velocity script, implemented as a set of widget extensions automatically available in the context of an executed Velocity script. Additionally, custom extensions can also be accessed.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;p&gt;When a widget extension method accepts a dictionary of options, those options can be passed using the Velocity syntax&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;%{ Key1 = $value1, Key2 = $value2 }&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the entire dictionary is passed as a formatted string.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Retrieve the current blog. If there is none, hide the widget
#set ($currentBlog = $core_v2_blog.Current.Id)
#if (!$curentBlog)
	$core_v2_widget.Hide()
#end

## Retrieve the 5 latest blog posts
#set ($blogPosts = $core_v2_blogPost.List(&amp;quot;%{ BlogId = $currentBlog.Id, PageSize = 5 }&amp;quot;))

#foreach ($blogPost in $blogPosts)
#beforeall
	&amp;lt;ul&amp;gt;
#each
		&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;$core_v2_encoding.HtmlAttributeEncode($blogPost.Url)&amp;quot;&amp;gt;$blogPost.Title&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
#afterall
	&amp;lt;/ul&amp;gt;
#nodata
	&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;
#end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3 id="getting_the_current_foreach_index"&gt;&lt;a name="Getting_the_current_foreach_index"&gt;&lt;/a&gt;Getting the current Foreach Index&lt;/h3&gt;
&lt;p&gt;If you want to track the current index you will need to store the index as a local variable.&amp;nbsp; Here is an example of how you can do this.&lt;/p&gt;
&lt;pre&gt;#set($index = 0)
#foreach($tag in $core_v2_tags.Current)
  #each
	 #set($index = $index + 1)
#end
&lt;/pre&gt;
&lt;h3 id="concatenating_strings"&gt;Concatenating strings&lt;a name="Gotcha_NVelocity_Macros_with_Bodies"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="color:#444444;font-weight:normal;"&gt;Oftentimes you will need to combine two or more strings and pass the result as a parameter to a method, to do this, place the variables within double quotes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;#set($newVal = &amp;quot;$val1$val2&amp;quot;)&lt;/pre&gt;
&lt;h3 id="adding_a_variable_to_the_end_of_a_url_before_a_period"&gt;&lt;a name="Adding_a_variable_to_the_end_of_a_URL_before_a_period"&gt;&lt;/a&gt;Adding a variable to the end of a URL before a period&lt;/h3&gt;
&lt;p&gt;You may need to pass a Velocity variable as part of a URL, and you may need to pass it at the end of the URL before a period.&amp;nbsp; For example, if you are creating a URL for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;api.ashx/v2/groups/$groupId/members/users/$userId.json&lt;/span&gt; where &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; is a local Velocity variable, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; will not be formatted correctly because it is looking for a property named json on &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt;.&amp;nbsp; To get around this, you can use the strict formatting option for Velocity variables, like the following&lt;/p&gt;
&lt;pre&gt;api.ashx/v2/groups/$groupId/members/users/${userId}.json&lt;/pre&gt;
&lt;h3 id="gotcha_cannot_set_a_null_value"&gt;&lt;a name="Gotcha_Cannot_set_a_null_value"&gt;&lt;/a&gt;Working with null values&lt;/h3&gt;
&lt;p&gt;When Velocity evaluates&lt;/p&gt;
&lt;pre&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;if&amp;nbsp;$someExtension.someMethod()&amp;nbsp;evaluates to&amp;nbsp;null,&amp;nbsp;$variable&amp;nbsp;will not be changed. It will still have its previous value. To reuse the&amp;nbsp;$variable&amp;nbsp;variable (in a&amp;nbsp;#foreach, for example), instead use:&lt;/p&gt;
&lt;pre&gt;#set ($variable = false)&lt;br /&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;This is how links widgets must be implemented.&amp;nbsp;&lt;/p&gt;
&lt;h3 id="programmatically_modifyingbuilding_dictionary_options"&gt;&lt;a name="Programmatically_Modifying_Building_IDictionary_Options"&gt;&lt;/a&gt;Programmatically modifying/building dictionary options&lt;/h3&gt;
&lt;p&gt;It is already possible to do calls like this&lt;/p&gt;
&lt;pre&gt;$core_v2_foo.Bar(42, &amp;quot;%{ key1 = &amp;quot;value&amp;quot;, key2 = &amp;quot;value2&amp;quot; }&lt;/pre&gt;
&lt;p&gt;Sometimes it is necessary to programmatically build the options dictionary for looping or logical reasons. This can be done as follows:&lt;/p&gt;
&lt;pre&gt;#set ($options = &amp;quot;%{}&amp;quot;)
$options.Add(newKey, &amp;quot;newValue&amp;quot;)&lt;/pre&gt;
&lt;p&gt;Try&amp;nbsp;&lt;code&gt;$core_help.Dump()&lt;/code&gt;ing&amp;nbsp;&lt;code&gt;$options&lt;/code&gt;&amp;nbsp;to see the full set of methods available for operating on the dictionary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Using Velocity in Widgets</title><link>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity/revision/1</link><pubDate>Fri, 14 Jun 2019 17:07:07 GMT</pubDate><guid isPermaLink="false">3d8b9043-6f89-469f-a437-4e17fba4ac00</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65087/using-velocity#comments</comments><description>Revision 1 posted to Developer Training by Ben Tiedt on 06/14/2019 17:07:07&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;Widget content is implemented using a version of the Velocity templating language.&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_the_Velocity_templating_language" name="When_should_I_use_the_Velocity_templating_language"&gt;&lt;/a&gt;When should I use the Velocity templating language?&lt;/h2&gt;
&lt;p&gt;Velocity is the server side templating language used by widgets. In addition to providing server-side templating, Velocity is used to perform server side requests against the [[api-documentation:Widget Extensions|Widget Extension Platform API]] including custom [[Widget Extensions]].&lt;/p&gt;
&lt;h2&gt;&lt;a id="Velocity_Language_Syntax" name="Velocity_Language_Syntax"&gt;&lt;/a&gt;Velocity Language Syntax&lt;/h2&gt;
&lt;h3&gt;&lt;a name="Variables_Properties_and_Methods"&gt;&lt;/a&gt;Variables, properties, and methods&lt;/h3&gt;
&lt;h4 id="variables_and_extensions"&gt;&lt;a name="Variables_and_Extensions"&gt;&lt;/a&gt;Variables and extensions&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Variable and extension names must start with a dollar sign and an alphabetic letter.&lt;/p&gt;
&lt;p&gt;When the value of the variable is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$variable&lt;/span&gt; will render the name of the variable and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!variable&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${variable}&lt;/span&gt; is the formal notation for variables and distinguishes variable references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${variable}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Properties"&gt;&lt;/a&gt;Properties&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference properties on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the value of the property is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Property&lt;/span&gt; will render the name of the extension and property and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Property&lt;/span&gt; will render nothing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Property}&lt;/span&gt; is the formal notation for properties and distinguishes property references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Property}this&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name="Methods"&gt;&lt;/a&gt;Methods&lt;/h4&gt;
&lt;pre&gt;$[!][{ ][a-z,A-Z][a-z,A-Z,0-9,-,_]*.[a-z,A-Z][a-z,A-Z,0-9,-,_]*([optional_parameter_list])[ }]&lt;/pre&gt;
&lt;p&gt;Dot-syntax is used to reference methods on variables and extensions.&lt;/p&gt;
&lt;p&gt;When the return value of the method is null, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$extension.Method()&lt;/span&gt; will render the name of the extension and method and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$!extesion.Method()&lt;/span&gt; will render nothing. If the return value is void, nothing will be rendered.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;${extension.Method()}&lt;/span&gt; is the formal notation for methods and distinguishes method references within text, for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;see${extension.Method()}this&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a name="Directives"&gt;&lt;/a&gt;Directives&lt;/h3&gt;
&lt;h4 id="set"&gt;&lt;a name="set"&gt;&lt;/a&gt;#set&lt;/h4&gt;
&lt;pre&gt;#set($reference = [argument])&lt;/pre&gt;
&lt;p&gt;Assigns a value to a variable or property where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$reference&lt;/span&gt; is a variable or property reference.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a method, variable, or property reference&lt;/li&gt;
&lt;li&gt;a literal boolean (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;true &lt;/span&gt;or &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;false&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal number (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[0-9]*.[0-9]*&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a literal string in single or double quotes&lt;/li&gt;
&lt;li&gt;an array definition (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[$item1, $item2, $item3,... $itemN]&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;a mathematic expression:&lt;/li&gt;
&lt;li&gt;Addition: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n + 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Subtraction: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n - 1)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Multiplication: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n * $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Division: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#set($n = $n / $x)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Modulus:&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; #set($n = $n % $x)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[argument] &lt;/span&gt;is a literal string, strings in double quotes will be parsed whereas strings in single quotes will not be parsed.&lt;/p&gt;
&lt;h4&gt;&lt;a name="if"&gt;&lt;/a&gt;#if&lt;/h4&gt;
&lt;pre&gt;#if([condition])&lt;br /&gt;&amp;nbsp; [script to execute when if condition is true]&lt;br /&gt;[&lt;br /&gt;#elseif([condition])&lt;br /&gt;&amp;nbsp; [script to execute when elseif condition is true]&lt;br /&gt;]*&lt;br /&gt;[&lt;br /&gt;#else&lt;br /&gt;&amp;nbsp; [script to execute if no conditions are true]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Conditionally renders templates where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[condition]&lt;/span&gt;is:
&lt;ul&gt;
&lt;li&gt;a Boolean expression:
&lt;ul&gt;
&lt;li&gt;Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x == $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt; $y)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt; 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Greater or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;gt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Less or Equal: &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if($x &amp;lt;= 100)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;a non-Boolean variable, property, method, or literal reference (true if not null, otherwise false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="padding:0;margin:0;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="foreach"&gt;&lt;/a&gt;#foreach&lt;/h4&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;[#each]&lt;br /&gt;&amp;nbsp; [script to execute for each item]&lt;br /&gt;[&lt;br /&gt;#before&lt;br /&gt;&amp;nbsp; [script to execute before each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#after&lt;br /&gt;&amp;nbsp; [script to execute after each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#between&lt;br /&gt;&amp;nbsp; [script to execute between each item]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#odd&lt;br /&gt;&amp;nbsp; [script to execute for every other item, including the first]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#even&lt;br /&gt;&amp;nbsp; [script to execute for every other item, starting with the second]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#nodata&lt;br /&gt;&amp;nbsp; [script to execute if $items is null or empty]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#beforeall&lt;br /&gt;&amp;nbsp; [script to execute before all items, if there are items]&lt;br /&gt;]&lt;br /&gt;[&lt;br /&gt;#afterall&lt;br /&gt;&amp;nbsp; [script to execute after all items, if there are items]&lt;br /&gt;]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Renders templates for each item within a collection of items where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$item&lt;/span&gt; is the variable containing each item in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; collection when executing &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt;, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#odd&lt;/span&gt;, and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#even&lt;/span&gt; scripts.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$items&lt;/span&gt; is a variable, property, or method resulting in a collection of items.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...] &lt;/span&gt;is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#each&lt;/span&gt; is the default template, so,&lt;/p&gt;
&lt;pre&gt;#foreach($item in $items)&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;is equivalent to&lt;/p&gt;
&lt;pre&gt;#foreach ($item in $items)&lt;br /&gt;#each&lt;br /&gt;&amp;nbsp; $item.Name&lt;br /&gt;#end&lt;/pre&gt;
&lt;h4&gt;&lt;a name="registerEndOfPageHtml"&gt;&lt;/a&gt;#registerEndOfPageHtml&lt;/h4&gt;
&lt;pre&gt;#registerEndOfPageHtml([key])&lt;br /&gt;&amp;nbsp; [script to render at the bottom of the completed HTML page]&lt;br /&gt;#end&lt;/pre&gt;
&lt;p&gt;Registers a block of HTML at the end of the completed HTML page where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is an optional variable, property, or literal string value identifying the unique key with which the contained markup should be registered.&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[script...]&lt;/span&gt; is any Velocity or literal text.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is not supplied, the contained script will always be added to the bottom of the completed HTML page. If the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[key]&lt;/span&gt; is supplied, the first &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#registerEndOfPageHtml&lt;/span&gt; directive executed will have its contained script added to the bottom of the completed page.&lt;/p&gt;
&lt;h4&gt;&lt;a name="evaluate"&gt;&lt;/a&gt;#evaluate&lt;/h4&gt;
&lt;pre&gt;#evaluate($script)&lt;/pre&gt;
&lt;p&gt;Execute a string as a Velocity script where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$script&lt;/span&gt; is a variable, property, or literal string containing Velocity script.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a name="stop"&gt;&lt;/a&gt;#stop&lt;/h4&gt;
&lt;pre&gt;#stop&lt;/pre&gt;
&lt;p&gt;Stops execution of the widget immediately.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#stop&lt;/span&gt; should only be used for debugging purposes. To hide a widget, use &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$core_widget.Hide() &lt;/span&gt;instead.&lt;/p&gt;
&lt;h4&gt;&lt;a id="T_931095879" name="T_931095879"&gt;&lt;/a&gt;##&lt;/h4&gt;
&lt;pre&gt;## [comment]&lt;/pre&gt;
&lt;p&gt;Identifies a comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is a single line of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;&lt;a id="T_755172541" name="T_755172541"&gt;&lt;/a&gt;#*&lt;/h4&gt;
&lt;pre&gt;#* [comment lines] *#&lt;/pre&gt;
&lt;p&gt;Identifies a multi-line comment where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;[comment]&lt;/span&gt; is one or more lines of unexecuted text.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_with_Velocity" name="Widget_Extension_Usage_with_Velocity"&gt;&lt;/a&gt;Widget Extension Usage with Velocity&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to velocity script, implemented as a set of widget extensions automatically available in the context of an executed Velocity script. Additionally, custom extensions can also be accessed.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;p&gt;When a widget extension method accepts a dictionary of options, those options can be passed using the Velocity syntax&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;%{ Key1 = $value1, Key2 = $value2 }&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the entire dictionary is passed as a formatted string.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## Retrieve the current blog. If there is none, hide the widget
#set ($currentBlog = $core_v2_blog.Current.Id)
#if (!$curentBlog)
	$core_v2_widget.Hide()
#end

## Retrieve the 5 latest blog posts
#set ($blogPosts = $core_v2_blogPost.List(&amp;quot;%{ BlogId = $currentBlog.Id, PageSize = 5 }&amp;quot;))

#foreach ($blogPost in $blogPosts)
#beforeall
	&amp;lt;ul&amp;gt;
#each
		&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;$core_v2_encoding.HtmlAttributeEncode($blogPost.Url)&amp;quot;&amp;gt;$blogPost.Title&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
#afterall
	&amp;lt;/ul&amp;gt;
#nodata
	&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;
#end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3 id="getting_the_current_foreach_index"&gt;&lt;a name="Getting_the_current_foreach_index"&gt;&lt;/a&gt;Getting the current Foreach Index&lt;/h3&gt;
&lt;p&gt;If you want to track the current index you will need to store the index as a local variable.&amp;nbsp; Here is an example of how you can do this.&lt;/p&gt;
&lt;pre&gt;#set($index = 0)
#foreach($tag in $core_v2_tags.Current)
  #each
	 #set($index = $index + 1)
#end
&lt;/pre&gt;
&lt;h3 id="concatenating_strings"&gt;Concatenating strings&lt;a name="Gotcha_NVelocity_Macros_with_Bodies"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="color:#444444;font-weight:normal;"&gt;Oftentimes you will need to combine two or more strings and pass the result as a parameter to a method, to do this, place the variables within double quotes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;#set($newVal = &amp;quot;$val1$val2&amp;quot;)&lt;/pre&gt;
&lt;h3 id="adding_a_variable_to_the_end_of_a_url_before_a_period"&gt;&lt;a name="Adding_a_variable_to_the_end_of_a_URL_before_a_period"&gt;&lt;/a&gt;Adding a variable to the end of a URL before a period&lt;/h3&gt;
&lt;p&gt;You may need to pass a Velocity variable as part of a URL, and you may need to pass it at the end of the URL before a period.&amp;nbsp; For example, if you are creating a URL for &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;api.ashx/v2/groups/$groupId/members/users/$userId.json&lt;/span&gt; where &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; is a local Velocity variable, &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt; will not be formatted correctly because it is looking for a property named json on &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;$userId&lt;/span&gt;.&amp;nbsp; To get around this, you can use the strict formatting option for Velocity variables, like the following&lt;/p&gt;
&lt;pre&gt;api.ashx/v2/groups/$groupId/members/users/${userId}.json&lt;/pre&gt;
&lt;h3 id="gotcha_cannot_set_a_null_value"&gt;&lt;a name="Gotcha_Cannot_set_a_null_value"&gt;&lt;/a&gt;Working with null values&lt;/h3&gt;
&lt;p&gt;When Velocity evaluates&lt;/p&gt;
&lt;pre&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;if&amp;nbsp;$someExtension.someMethod()&amp;nbsp;evaluates to&amp;nbsp;null,&amp;nbsp;$variable&amp;nbsp;will not be changed. It will still have its previous value. To reuse the&amp;nbsp;$variable&amp;nbsp;variable (in a&amp;nbsp;#foreach, for example), instead use:&lt;/p&gt;
&lt;pre&gt;#set ($variable = false)&lt;br /&gt;#set ($variable = $someExtension.someMethod())&lt;/pre&gt;
&lt;p&gt;This is how links widgets must be implemented.&amp;nbsp;&lt;/p&gt;
&lt;h3 id="programmatically_modifyingbuilding_dictionary_options"&gt;&lt;a name="Programmatically_Modifying_Building_IDictionary_Options"&gt;&lt;/a&gt;Programmatically modifying/building dictionary options&lt;/h3&gt;
&lt;p&gt;It is already possible to do calls like this&lt;/p&gt;
&lt;pre&gt;$core_v2_foo.Bar(42, &amp;quot;%{ key1 = &amp;quot;value&amp;quot;, key2 = &amp;quot;value2&amp;quot; }&lt;/pre&gt;
&lt;p&gt;Sometimes it is necessary to programmatically build the options dictionary for looping or logical reasons. This can be done as follows:&lt;/p&gt;
&lt;pre&gt;#set ($options = &amp;quot;%{}&amp;quot;)
$options.Add(newKey, &amp;quot;newValue&amp;quot;)&lt;/pre&gt;
&lt;p&gt;Try&amp;nbsp;&lt;code&gt;$core_help.Dump()&lt;/code&gt;ing&amp;nbsp;&lt;code&gt;$options&lt;/code&gt;&amp;nbsp;to see the full set of methods available for operating on the dictionary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>