Using variables in export

I trying to use a variable in an export script. I know its possible in a stamp like

var tmp($MyNumber); collect_if(all,$MyNumber=tmp,$Name)

Is there a way to do this in an export script?

^value(collect_if(all,$MyNumber>5 & $MyNumber<8,$MyTitle))^

In the example above I would like to use variables for 5 and 8 to select a range.

Thanks for your help!

Instead of value try action.

I don’t believe you can invoke/use an action code var inside a ^value()^. Also if you use a var in an ^action()^ sections of a template the var only works inside that code and not throughout the template. So, if you need to use a variable value in a ^value()^ you will have to use an attribute to cache the value. Here is a simple value (the section ^action()^ section is simply to rest the the cache attribute):

^action(
var tmp($MyNumber);
$MyList = collect_if(all,$MyNumber=tmp,$Name);
)^
^value($MyList.format(", "))^
^action(
$MyList=;
)^

The whitespace line-beaks in the action sections are for clarity only.

In terms of HTML output, line-breaks inside ^action()^ are ignored but line breaks before/after the code are emitted. Thus the above would emit 3 discrete lines to HTML, first/last will emtpy lines and the middle one will have the ^value()^ output. To use one line of output leave no breats between the export codes, like so:

^action(
var tmp($MyNumber);
$MyList = collect_if(all,$MyNumber=tmp,$Name);
)^^value($MyList.format(", "))^^action(
$MyList=;
)^

We don’t have to worry about line breaks inside the ^action()^ codes. :slight_smile:

1 Like

Thanks for your prompt reply. Much appreciated! Will try it out to get a range like navigation for my notes.

1 Like