Lasso Soft Inc. > Home

  • Articles

Inline Parameters

Taken from the tip of the week for May 30, 2008, this article discusses how an inline processes its parameters and how an array of common parameters can be used to make your code easier to maintain.

Inlines form the core of many pages written in Lasso. There are often many inlines on a page, nested or otherwise. This tip describes some techniques for dealing with inline parameters including re-using common parameters and creating dynamic inlines.

Overview

An [Inline] tag accepts a series of parameters that determine the database action which is to be performed. The parameters are read by Lasso in the order they are specified in the tag.

Some parameters like -Database, -Table, -MaxRecords, and -SkipRecords can only be specified once. The last instance of each parameter is the value that Lasso uses. Each inline can have one action (-Search, -Add, -Update, etc.). The last action specified will be used.

Other parameters like search terms, 'Field_Name'='Value', and sort parameters, -SortField='Field_Name', can be specified multiple times. Lasso will store these parameters and pass them to the data source so the proper SQL statement can be generated.

An inline will also accept an array of parameters. Each of the elements of the array are inserted into the array as if they had been typed out at the location of the array. This allows parameters for an inline to be assembled in a variable and then passed all at once to an inline.

Re-Using Inline Parameters

Throughout a page or your entire site you'll notice that many inlines contains the same set of parameters. Often an entire site will use the same database, table, keyfield name, log-level, max records value, etc.

This is a typical inline which finds "John Doe" in the specified database. If we are working on an internal site we may find that most of our inlines reference the "myCompany" database. We may want to make sure that we default to -MaxRecords='all' rather than the built-in default of 50.

[Inline(-Log='none',
      -Database='myCompany',
      -Table='People',
      -KeyField='id',
      -MaxRecords='all',
      -Search',
      -Op='eq', 'first_name'='John',
      -Op='eq', 'last_name'='Doe')]
    ...
  [/Inline]

 

We can separate out the common parameters into an array and then pass that array as the first parameter to the inline. First, we create a variable $peopleInline which is defined as an array with the common parameters. We could define this variable in a shared include for use throughout a site or we could define it at the top of the page.

Note that the inline tag will only accept an array. It does not parse a string variable to look for parameters, so you can't build $peopleInline as a string.

[Var('peopleInline') = Array(
      -Log='none',
      -Database='myCompany',
      -Table='People',
      -KeyField='id',
      -MaxRecords='all')]

 

Next, in each inline that references the same database and table we insert the variable $peopleInline rather than specifying the -Database-Table, and other parameters explicitly.

[Inline($peopleInline,
      -Search',
      -Op='eq', 'first_name'='John',
      -Op='eq', 'last_name'='Doe')]
    ...
  [/Inline]

 

If we make this change to multiple inlines and later find that we want to change the log-level for debugging, or any other shared parameter, we can make that change one time to the $peopleInline variables and it will be inherited throughout our site.

Overriding Parameters

We can override parameters from the $peopleInline variable by specifying them explicitly within the inline after the $peopleInline variable. Since Lasso will use the last parameter of each type specified, our explicit -MaxRecords will override the -MaxRecords within $peopleInline.

The following code will find only the first 10 matches for "John Doe".


[Inline($peopleInline,
      -Search',
      -MaxRecords=10,
      -Op='eq', 'first_name'='John',
      -Op='eq', 'last_name'='Doe')]
    ...
  [/Inline]

 


This override behavior allows us to set up a collection of defaults for all inlines on the page, but to use whatever specific values we need in each inline.

Dynamic Inlines

We can extend the technique described above to create dynamic inlines. This can be useful when we have logic that modifies not just the values within the inline, but also the number of parameters in the inline.

We create a variable $localInline as an array which is going to contain the parameters for our inline.

Var('localInline') = Array;

We then insert each of the parameters for the inline into this array. We might insert the -Database-Table, and other parameters explicitly as shown below. The action -Search is also inserted into the variable since we are going to specify all the parameters for the inline dynamically, rather than specifying some in the inline itself.

$localInline->Insert(-Log='none');
  $localInline->Insert(-Database='myCompany');
  $localInline->Insert(-Table='People');
  $localInline->Insert(-KeyField='id');
  $localInline->Insert(-MaxRecords='all');
  $localInline->Insert(-Search='');

 

Name/Value parameters can be inserted in the same fashion. Here, the parameters to find "John Doe" are inserted into the inline. Note that the operator must be inserted first, then the name/value parameter.

$localInline->Insert(-Op='eq');
  $localInline->Insert('first_name'='John');
  $localInline->Insert(-Op='eq');
  $localInline->Insert('last_name'='Doe');

 

Conditionals can be used to determine which parameters are added to the inline. For example, this code checks what field should be used to sort the inline and inserts different -SortField and -SortOrder parameters accordingly.

If($sortfield >> 'first');
    $localInline->Insert(-SortField='First_Name');
    $localInline->Insert(-SortOrder='Ascending');
  Else($sortfield >> 'last');
    $localInline->Insert(-SortField='Last_Name');
    $localInline->Insert(-SortOrder='Descending');
  /If;

 

Now the entire dynamic variable $localInline is passed into the inline as a single array parameter. Since the variable contains the full specification for the inline action we do not need any other parameters in the inline itself.

[Inline($localInline)]
    ...
  [/Inline]

 


However, should we need to override some of the values in the dynamic variable $localInline we could do so by adding additional parameters within the [Inline] tag.

More Information

More information about the inline tags and database action parameters be found in the Language Guide or in the Lasso Reference.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft