Tag: Difference between revisions

From Tygron Support wiki
Jump to navigation Jump to search
No edit summary
 
(56 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Text in panels can contain special tags that are replaced by the {{software}} based on the project data, session and the context (owner, maplink etc.) of the panel. This page shows the supported panel tags.
When requesting the text content of a panel through any of the web endpoints, the content returned is formatted and tags are replaced. These tags can be general tags, values of [[attribute]]s and [[global]]s, as well as [[Select (TQL)|TQL Select statements]].


===General tags===
Tags should always be preceded by a dollar sign ($), for example:
* $PROJECT_NAME, name of the project.
<code>$SELECT_GLOBAL_WHERE_NAME_IS_FOO</code>
* $TOKEN, token of your project's session.


===Web tags===
==TQL Tags==
* $LIB_CUSTOM, the name of the custom javascript library.
[[Select (TQL)|Select queries]] can also be added to a text panel to obtain Project Session data. These select queries must always be preceded by a dollar sign ($) and are allowed to end with a dollar sign ($) as well. Adding or adjusting select queries require a [[Calculation Cloud|recalculation]].
Once the results of the defined select queries are calculated, the queries are replaced with the calculated values.


===Contextual tags===
For example, the TQL tags for obtaining the name of a Neighborhood with Item ID 4, that will be replaced successfully are <code>$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_4</code> and <code>$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_4$</code>
* $NAME, name of the panel.
* $ID, id of the panel.
* $STAKEHOLDER_ID, the [[ID]] of the owner of the panel, if it has one. -1 if it has none.
* $STAKEHOLDER, the name of the owner of the panel, if it has one. Empty text if it has none.


===Attributes tags===
===TQL Tags with X and Y Queries===
* $ATTRIBUTE_ATTRIBUTENAME, where ATTRIBUTENAME is the TQL approved attribute name. This allows users to acquire attributes stored in this panel, which can change based on calculations of indicators or other panels.
A TQL Tag with a [[X (TQL)|X]], [[XA (TQL)|XA]], [[XK (TQL)|XK]] or [[XC (TQL)|XC]] clause is evaluated to an array of values, '''without''' the outer brackets. This may lead to issues when used inside [[JavaScript]] (&lt;script&gt;) parts of a panel.
* $GLOBAL_GLOBALNAME, where GLOBALNAME is the TQL approved global name. This also allows users to acquire values of globals stored in your project, which can change based on calculation of indicators or other panels.
 
For Example, a panel with the following content for a project with three neighborhoods names "North City", "East City" and "West City"
 
<code>$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X</code>
 
is evaluated and replaced with:
 
<code>"North City" , "East City", "West City"</code>
 
When assigning this to a variable, the TQL Tag with an X query should therefore be put between brackets:
 
<code>let names = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X];</code>
 
is evaluated and replaced with:
 
<code>let names = ["North City", "East City", "West City"];</code>
 
In the case of a numerical query:
 
<code>let landsizes = [$SELECT_LANDSIZE_WHERE_NEIGHBORHOOD_IS_X];</code>
 
is evaluated and replaced with their calculated land sizes, for example:
 
<code>let landsizes = [100.0 , 240.25, 146.8];</code>
 
Similarly, a TQL Tag with  [[Y (TQL)|Y]], [[YA (TQL)|YA]], [[YK (TQL)|YK]] or [[YC (TQL)|YC]] clause is evaluated to an array of arrays of values:
 
<code>let namesMatrix = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_Y];</code>
 
is evaluated and replaced with:
 
<code>let namesMatrix = [["North City"], ["East City"], ["West City"]];</code>
 
==HTML, CSS and Javascript==
Text panel content is always returned as HTML; if it isn't already, <code>&lt;html&gt;</code> and <code>&lt;body&gt;</code> tags are automatically added. Javascript can defined and used inside <code>&lt;script&gt;</code> tags.
 
==General Tags==
{|class=wikitable
!Name
!Description
|-
| $PROJECT_NAME
| Formatted project name
|-
| $PLATFORM_DESCRIPTION
| Client description of the {{software}}
|-
| $LIB_CUSTOM
| Lower-case underscored project name
|-
| $TITLE
| Title of the panel
|-
| $CSS
| Replaced with relative stylesheet link: <code>&lt;link rel=\"stylesheet\" type=\"text/css\" href=\"tygron.css?token=$TOKEN\"&gt;</code>
|-
| $LIB_PLOTLY
| Replaced with header script entry for Plotly; <code>&lt;script src=\"plotly.js?token=$TOKEN\" type=\"text/javascript\"&gt;</script>
|-
| $TOKEN
| Web token or Api token, depending on the context.
|-
| $STAKEHOLDER_ID
| id of the stakeholder; Stakeholder is obtained from the accessing web stakeholder or from a specified stakeholder id in the end point.
|-
| $STAKEHOLDER_SHORT
| short name of the stakeholder; Stakeholder is obtained from the accessing web stakeholder or from a specified stakeholder id in the end point.
|-
| $STAKEHOLDER
| name of the stakeholder; Stakeholder is obtained from the accessing web stakeholder or from a specified stakeholder id in the end point.
|-
|}
 
==Legacy Tags==
The following tags are deprecated and not to be used anymore, but kept for backwards compatibility.
{|class=wikitable
!Name
!Description
|-
| $SESSION
| Replaced with empty string
|-
| $SLOT
| Replaced with empty string
|-
| $ID
| Replaced with the id of the linked item.
|-
| $NAME
| Replaced with the name of the linked item.
|-
| $ATTRIBUTE_
| Replaced with the value for the attribute specified after <code>$ATTRIBUTE_</code>, obtained from the linked item.
|-
| $GLOBAL_
| Obtains the value of the [[Global]] specified after <code>$GLOBAL_</code> from the linked item.
|}
 
==Limitations==
Tags, [[Globals]], [[attribute]]s, and [[Select (TQL)|TQL Select statements]] are only replaced in the text content and cannot be generated dynamically via JavaScript.
Generally only capital letters, numbers, underscores are supported for tags. Characters such as <code>, ( ) [ ] { } &lt; and &gt</code> cannot be used inside tags.
 
In the following example, the Select statements are not properly replaced and will therefore not work.
<syntaxhighlight>
const tableData = [];
for (const nh of neighborhoods) {
  const nameQuery = `$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_${nh.id}`;
  const valueQuery = `$SELECT_ATTRIBUTE_WHERE_NEIGHBORHOOD_IS_${nh.id}_AND_NAME_IS_INHABITANTS`;
  tableData.push({
    name: nh.name,
    inhabitants: valueResult[0] // TQL returns an array of results
  });
}
</syntaxhighlight>
 
Instead, the select statement should be written as follows:
<syntaxhighlight copy>
const neighborhoodNames = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X];
const neighborhoodInhabitants = [$SELECT_ATTRIBUTE_WHERE_NEIGHBORHOOD_IS_X_AND_NAME_IS_INHABITANTS];
 
const tableData = [];
for(let n = 0; n < neighborhoodNames.length && n < neighborhoodInhabitants.length; n++){
  tableData.push({
    name: neighborhoodNames[n];
    inhabitants: neighborhoodInhabitants[n];
  });
}
</syntaxhighlight>
 
For further specification details, see [[Global]], [[Attribute]] and [[Select (TQL)]] respectively.
 
{{article end
| notes=
* Tags can also be used in the output of [[Panel]]s based on an [[Excel]], and in [[Indicator]]s, with the exception of TQL Tags, which are not evaluated. These should be put in the Excel itself instead using [[Excel#Naming cells|names]].
|seealso=
* [[Panel]]
* [[Template Panel]]
* [[Global]]
* [[Attribute]]
* [[Select (TQL)]]
* [[JavaScript]]
|api=
* [[Api session items panels]]
* [[Api session event editor panel]]
}}

Latest revision as of 09:07, 12 November 2026

When requesting the text content of a panel through any of the web endpoints, the content returned is formatted and tags are replaced. These tags can be general tags, values of attributes and globals, as well as TQL Select statements.

Tags should always be preceded by a dollar sign ($), for example: $SELECT_GLOBAL_WHERE_NAME_IS_FOO

TQL Tags

Select queries can also be added to a text panel to obtain Project Session data. These select queries must always be preceded by a dollar sign ($) and are allowed to end with a dollar sign ($) as well. Adding or adjusting select queries require a recalculation. Once the results of the defined select queries are calculated, the queries are replaced with the calculated values.

For example, the TQL tags for obtaining the name of a Neighborhood with Item ID 4, that will be replaced successfully are $SELECT_NAME_WHERE_NEIGHBORHOOD_IS_4 and $SELECT_NAME_WHERE_NEIGHBORHOOD_IS_4$

TQL Tags with X and Y Queries

A TQL Tag with a X, XA, XK or XC clause is evaluated to an array of values, without the outer brackets. This may lead to issues when used inside JavaScript (<script>) parts of a panel.

For Example, a panel with the following content for a project with three neighborhoods names "North City", "East City" and "West City"

$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X

is evaluated and replaced with:

"North City" , "East City", "West City"

When assigning this to a variable, the TQL Tag with an X query should therefore be put between brackets:

let names = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X];

is evaluated and replaced with:

let names = ["North City", "East City", "West City"];

In the case of a numerical query:

let landsizes = [$SELECT_LANDSIZE_WHERE_NEIGHBORHOOD_IS_X];

is evaluated and replaced with their calculated land sizes, for example:

let landsizes = [100.0 , 240.25, 146.8];

Similarly, a TQL Tag with Y, YA, YK or YC clause is evaluated to an array of arrays of values:

let namesMatrix = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_Y];

is evaluated and replaced with:

let namesMatrix = [["North City"], ["East City"], ["West City"]];

HTML, CSS and Javascript

Text panel content is always returned as HTML; if it isn't already, <html> and <body> tags are automatically added. Javascript can defined and used inside <script> tags.

General Tags

Name Description
$PROJECT_NAME Formatted project name
$PLATFORM_DESCRIPTION Client description of the Tygron Platform
$LIB_CUSTOM Lower-case underscored project name
$TITLE Title of the panel
$CSS Replaced with relative stylesheet link: <link rel=\"stylesheet\" type=\"text/css\" href=\"tygron.css?token=$TOKEN\">
$LIB_PLOTLY Replaced with header script entry for Plotly; <script src=\"plotly.js?token=$TOKEN\" type=\"text/javascript\"></script>
$TOKEN Web token or Api token, depending on the context.
$STAKEHOLDER_ID id of the stakeholder; Stakeholder is obtained from the accessing web stakeholder or from a specified stakeholder id in the end point.
$STAKEHOLDER_SHORT short name of the stakeholder; Stakeholder is obtained from the accessing web stakeholder or from a specified stakeholder id in the end point.
$STAKEHOLDER name of the stakeholder; Stakeholder is obtained from the accessing web stakeholder or from a specified stakeholder id in the end point.

Legacy Tags

The following tags are deprecated and not to be used anymore, but kept for backwards compatibility.

Name Description
$SESSION Replaced with empty string
$SLOT Replaced with empty string
$ID Replaced with the id of the linked item.
$NAME Replaced with the name of the linked item.
$ATTRIBUTE_ Replaced with the value for the attribute specified after $ATTRIBUTE_, obtained from the linked item.
$GLOBAL_ Obtains the value of the Global specified after $GLOBAL_ from the linked item.

Limitations

Tags, Globals, attributes, and TQL Select statements are only replaced in the text content and cannot be generated dynamically via JavaScript. Generally only capital letters, numbers, underscores are supported for tags. Characters such as , ( ) [ ] { } < and &gt cannot be used inside tags.

In the following example, the Select statements are not properly replaced and will therefore not work.

const tableData = [];
for (const nh of neighborhoods) {
  const nameQuery = `$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_${nh.id}`;
  const valueQuery = `$SELECT_ATTRIBUTE_WHERE_NEIGHBORHOOD_IS_${nh.id}_AND_NAME_IS_INHABITANTS`;
  tableData.push({
    name: nh.name,
    inhabitants: valueResult[0] // TQL returns an array of results
  });
}

Instead, the select statement should be written as follows:

const neighborhoodNames = [$SELECT_NAME_WHERE_NEIGHBORHOOD_IS_X];
const neighborhoodInhabitants = [$SELECT_ATTRIBUTE_WHERE_NEIGHBORHOOD_IS_X_AND_NAME_IS_INHABITANTS];

const tableData = [];
for(let n = 0; n < neighborhoodNames.length && n < neighborhoodInhabitants.length; n++){
  tableData.push({
    name: neighborhoodNames[n];
    inhabitants: neighborhoodInhabitants[n];
  });
}

For further specification details, see Global, Attribute and Select (TQL) respectively.

Notes

  • Tags can also be used in the output of Panels based on an Excel, and in Indicators, with the exception of TQL Tags, which are not evaluated. These should be put in the Excel itself instead using names.

See also

API Endpoints