Back

Create a "Parse VTL" Widget Structure

Description

This example allows you to execute the code in vtl files by simply browsing for them and saving a piece of widget content.

Tired of having to type out dotParse statements and paths to your vtl files to execute their velocity code in a simple widget? Just create this widget structure on your site, add a file field, and add the simple code below to the widget code field.

The code finds the file with a dotcontent.find and then the variable called myHost is set the the host name of where the vtl file lives so that the path that is parsed can include the host and always get the right vtl file, no matter what host it lives on.  Then the code below will automatically find the path to your file and assign it to the codeshare-detail.vtl variable.  Then the host and filepath are both passed to a dotParse statement to execute the vtl file.

supply it to a dotParse statement which will execute your vtl file code on the page that you place the widget content on.

*The filefield on my widget structure has the velocity variable name of "vtlFile" - make sure to change the code if your file field has a different velocity variable name.

Code

##Feed the filetool the identifier of your file in the widget content and the parameter "true" which indicates the file is "live" or published.  In this example, the file field on my widget has the velocity variable name set to "vtlFile"

#set($myFile = $dotcontent.find($!{vtlFile}))
#set($myHost=$myFile.host.hostName)
#set($filePath=$filetool.getFile("$!{vtlFile}",true))

#dotParse("//$myHost$filePath.getURI()")