LassoScript Utility
Basics Browse Detail

Lasso Reference

The Lasso Reference is the online documentation for Lasso Professional. It includes documentation of every tag supported by Lasso. Use the browse tab to see a list of the more than one thousand tags which are available to do everything from searching databases to building PDFs to creating your own object-oriented data types.

Throughout this reference tags are identified in square brackets with internal capitalization, e.g. [Field] or [Inline] ... [/Inline]. A link to any tag can be created by typing the URL of the Lasso Reference followed by the tag name. The Lasso Reference also supports linking to category names, type names, and more.

[Field] - http://reference.lassosoft.com/LassoReference.LassoApp?[Field]
[Inline] - http://reference.lassosoft.com/LassoReference.LassoApp?[Inline]
PDF Tags - http://reference.lassosoft.com/LassoReference.LassoApp?PDF
Lasso 8.6 Tags - http://reference.lassosoft.com/LassoReference.LassoApp?Lasso8.5
Container Tags - http://reference.lassosoft.com/LassoReference.LassoApp?Container
New Tags - http://reference.lassosoft.com/LassoReference.LassoApp?New

LassoScript

LassoScript is the language of Lasso Professional and is used to create all of the dynamic aspects of your Web site. LassoScript can be embedded in HTML code to display and format data from database searches. Blocks of LassoScript can be used to perform data processing with or without output to the page. This page provides a quick introduction to LassoScript. Please consult the Lasso Language Guide for complete documentation.

Embedding

LassoScript can be embedded into your Web pages in two ways. The first is to enclose one or more tags in square brackets. If more than one tag is specified, then individual tags are ended with semi-colons. Square brackets are often used when embedding LassoScript within HTML tags since the brackets help make the Lasso tags stand out from the surrounding markup. The following tag outputs the current date and time formatted using the SQL standard.

[Date_Format: Date, -Format='%Q %T'] -> 2024-10-05 19:00:54

The second method is to use a <?LassoScript ... ?> container. The syntax of the tags within is exactly the same as with square brackets. Individual tags are ended by semi-colons (and usually written on individual lines). Lasso won't output any of the white space contained in the LassoScript so formatting and comments can be used to make your code easier to read. The following tags have the same output as the tag above, but use a variable to store the date which is to be output.

<?LassoScript Var('MyDate' = Date); Date_Format($MyDate, -Format='%Q %T'); ?>

2024-10-05 19:00:54

Syntax Style

Lasso supports two different methods of writing LassoScript syntax. The first is colon syntax. The tag name is followed by a colon and then each of the parameters of the tag separated by commas. If necessary, tags are ended by a semi-colon.

[Var: 'MyResult' = (String_Uppercase: 'The quick brown fox')]

The second method is parentheses syntax. The tag name is followed by a pair of parentheses which contain all of the parameters of the tag separated by commas. If necessary, the closing parenthesis is followed by a semi-colon. This syntax more closely matches the syntax of JavaScript and other programming languages.

[Var('MyResult' = String_Uppercase('The quick brown fox'))]

The two syntax styles can be mixed and matched even within the same expression. Both styles are used throughout this reference, but most examples are only shown in one style or the other.

Parameters

Lasso tags accept several different types of parameters. The most basic parameter is a simple value like 'The quick brown fox' as in [String_Uppercase: 'The quick brown fox']. Some tags require named parameters or keywords. In Lasso parameter names are always preceded by a hyphen. For example, the [Date_Format] tag above has a parameter named -Format whose value is specified as -Format='%Q %T'. Keywords are specified like named parameters, but do not have a value. For example, a Greenwich Mean Time date can be created using the [Date] tag with a -GMT keyword as in [Date: -GMT]. Finally, some tags accept name/value parameters. The [Map] tag accepts name/value parameters to define the initial values of the map as in [Map: 'name'='value'].

Variables

Variables can be used to store temporary values and calculated results. Variables are normally available only within the context of a page. A variable is created using the [Var] tag. The tag [Var: 'name'='value'] creates a variable 'name' with the specified value. The value can be the result of any expression or tag.

Variable values can be retrieved using the [Var] tag with just a name. The tag [Var: 'name'] retrieves the value of the variable 'name'. Variable values can also be retrieved using the shortcut $name. This shortcut can be used to assign a new value to an existing values as in [$name = 'new value'], but cannot be used to create a new variable.

Lasso supports global variables through the [Global] tag which creates variables that can be accessed from any page in a site. Local variables can also be created within the context of a custom tag (Lasso's function abstraction). See below for more details

Encoding

By default Lasso automatically HTML encodes the output of tags so the value returned by the tag will be displayed properly within the Web browser. For example, the value returned by the tag [Field: 'description'] will be automatically encoded. If this field contains angle brackets they will be encoded as &lt; and &gt; so that they display to the site visitor.

[field: 'description'] <b>Bold Text</b>

In order to have the Web browser display rendered HTML tags it is necessary to tell Lasso not to encode the value using an encoding keyword such as -EncodeNone. The following tag outputs the value of the field without any encoding [Field: 'description', -EncodeNone]. Values can also be encoded for inclusion in a URL using -EncodeStrictURL and for XML validation using -EncodeXML.

[field: 'description', -EncodeNone] Bold Text

Expressions

Lasso supports inline expressions for math calculations, string manipulations, and comparisons. The + - * / % symbols perform the common math operations. Lasso supports both integer and decimal values. If either side of an expression is a decimal value then a decimal value is returned.

[4 + 5] 9 [4 * 5] 20 [100 / 13.0] 7.692308

Lasso also supports simple string manipulations using the + - * symbols. String values can be concatenated using the + symbol. Substrings can be deleted using the - symbol. And, a string can be repeated using the * symbol with an integer right hand side. Note that if the value on either side of a symbol is a string then the result will be a string.

['string' + ' and more'] string and more ['string' - 'ring'] st ['a' * 4] aaaa

Lasso supports a wide range of comparison symbols. The == and != symbols test for equality or inequality and automatically cast values in order to perform the comparison. The string '1', the integer 1, the decimal 1.0, and the boolean value true are all considered equal as are the empty string '', the integer 0, the decimal 0.0, and the boolean value false. The equivalence symbols === and !== compare both value and type. The > < <= >= symbols can be used on either numbers or strings. The contains symbol >> (and its complement !>> not contains) can be used to test whether a string >> contains a sub-string or if a compound data type such as an array or map contains an element. Comparison expressions can be combined with logical and && or logical or || symbols or negated with the logical not symbol !. Parentheses should be used to group expression.

['45' == 45] true ['45' === 45] false ['string' >> 'ring'] true [(Array: 1, 2, 3) >> 2] true [($value > 1) && ($value < 10)] true

Control

Lasso has several tags which allow for conditional execution of code, loops, and for including other LassoScript files within the current Lasso page.

Another Lasso page can be included in the current Lasso page using the [Include] tag. For example, [Include: 'mytags.lasso'] will include the file mytags.lasso within the current Lasso page.

Conditional execution is controlled using the [If] ... [/If] tags. The opening tag should include an expression which returns true or false. Multiple [Else] tags can be used within the [If] ... [/If] container. If the [Else] tag includes an expression then it functions as an "else if" executing the code following the tag only if that expression returns true. If the [Else] does not have a parameter then it functions as the default branch for the conditional. There can only be one default [Else] and it should be specified last.

[If: $name == 'value one'] ... Code For Value One ... [Else: $name = 'value two'] ... Code For Value Two ... [Else] ... Default Code ... [/If]

Code can be repeated a number of times using the [Loop] ... [/Loop] tags. For example, [Loop: 5] ... [/Loop] would process the code within five times. [Loop_Count] can be used within a loop to output which repetition is currently being processed. [Loop_Abort] can be used to halt a loop and [Loop_Continue] can be used to halt one reptition of a loop and jump to the start of the next repetition.

[Loop: 10] ... Repetition [Loop_Count] ... [/Loop]

The [Loop_Count], [Loop_Abort], and [Loop_Continue] tags can be used with any Lasso container tags which loop including [Records] ... [/Records] for looping through each record in the results of an inline database query, [Iterate] ... [/Iterate] for looping through each element of a compound data type in turn, [While] ... [/While] for looping indefinitely until a condition becomes false, and others.

Data Types

Lasso has many data types which allow data to be manipulated or provide access to network or file system resources. The basic data types include string, integer, decimal, and boolean. Each type has a constructor, e.g. [String], which can be used to create an instance of that type. The constructor [String: 'My String Value'] is equivalent to the shortcut 'My String Value' Strings are represented internally using Unicode. Raw bytes are represented by a byte stream whose creator is [Bytes].

Compound data types in Lasso include arrays, sets, maps, queues, stacks, and more. An array of data is created using [Array: 'Monday', 'Tuesday'] or stored in a variable using [Var: 'myArray' = (Array: 'Monday', 'Tuesday')]. Arrays (and other types) are manipulated through their member tags. The tag [Array->Insert] adds a new element to the array, e.g. [$myArray->(Insert: 'Wednesday')]. This tag modifies the array in-place and returns no value. See the "Array" category for a full list of compound data types and their members tags.

[Var: 'myArray' = (Array: 'Monday', 'Tuesday')] [$myArray->(Insert: 'Wednesday')] [$myArray->(Remove: 'Monday')] [$myArray]

array: (Tuesday), (Wednesday)

Other data types in Lasso include [RegExp] which allows regular expressions to be compiled and applied to string values, [File] for manipulating files, [Net] for file access, [Email_POP] which provides access to POP email servers, [PDF_Doc] which allows Portable Document Format files to be created, [XML] which allows XML documents to be created or parsed, and many more.

Database Operations

All database operations in Lasso occur through the [Inline] ... [/Inline] tags. Inlines can be used to perform database searches or to add, updated, or delete records from a database. Database operations can be specified using Lasso's built-in database abstraction language or with SQL statements.

For example, a database search of the "People" table of a "Contacts" database can be specified as follows. This query uses Lasso's database abstraction language to specify a search for all records where the "Age" field is greater than or equal to 18, but less than 35. The advantage of using Lasso's database abstraction is that the same syntax can be used across any data sources which Lasso supports.

[Inline: -Search, -Database='Contacts', -Table='People', -op='gte', 'age'=18, -op='lt', 'age'=35] [Records] [Field: 'First Name'] [Field: 'Last Name'] [Field: 'Age'] [/Records] [/Inline]

John Doe 25
Jane Doe 35

The same query could also be written using standard SQL as follows. Some advanced statements like JOIN, UNION, and ALTER need to be specified as SQL since they do not have analogues in Lasso's built-in data source independent query language.

[Inline: -Database='Contacts', -SQL='SELECT * FROM people WHERE age >= 18 AND age < 35'] [Records] [Field: 'First Name'] [Field: 'Last Name'] [Field: 'Age'] [/Records] [/Inline]

John Doe 25
Jane Doe 35

Custom Tags

Lasso's function abstraction is called a custom tag. Custom tags allow a portion of LassoScript to be encapsulated as a tag which can be called using the same methods as any built-in tag. For example, the following code defines a simple custom tag which squares the value which is passed into it. The tag uses local variables which functions exactly like a page variables, but are only accessible within the custom tag. The required parameter "value" is automatically created as a local variable. The tag [Local] and shortcut #name are used to access local variables. The tag [Net] is used to return the value of the tag.

[Define_Tag: 'mySquare', -Required='Value'] [Local: 'result' = #value * #value] [Return: #result] [/DefineTag]

[mySquare: 4] 16

Lasso supports both required and optional parameters for custom tags. Custom container and looping container tags can be created. Custom tags can operate asynchronously (in a separate thread) from the page which executes them. See the Lasso Language Guide for full details about creating custom tags.

Lasso also supports creating custom data types which can inherit from the built-in types or from other custom types. Custom data types support overloading of the math and comparison symbols, automatic serialization and deserialization, and more.

More Information

This primer offers a quick introduction to Lasso, but only scratches the surface of what is possible with this language. See the Lasso Language Guide for full details about Lasso's syntax, embedding methods, symbols, data types, and tags.

Much of the power of Lasso comes through the built-in tags. This Lasso Reference includes documentation of more than one thousand Lasso tags. You can get a feel for the breadth of possibilities by browsing through the tag categories.