Using Jinja in Quickbase Pipelines – Quickbase Help
Using Jinja in Quickbase Pipelines – Quickbase Help
Using Jinja in Quickbase Pipelines – Quickbase Help
Search
Quickbase Pipelines uses Jinja templating to enable dynamic expressions, filters, and access to variables, by providing Python-like expressions while
ensuring that the templates are evaluated in a sandbox.
Jinja is a modern and designer-friendly templating language for Python. It is a text-based language and thus can be used to generate any markup as
well as source code.
Pipelines is currently supporting Jinja2 2.11.3, for various formatting within pipeline steps.
IN THIS ARTICLE
http://jinja.quantprogramming.com/
https://jinja.palletsprojects.com/en/2.11.x/templates/
Statements
For statements use {% ... %}
Expressions
For expressions use {{ }} to print to the template output. For example {{ customer['first_name'] }} , prints the content in between the
curly brackets to the template output.
run_id =
The alphanumeric identifier for a single run of a Pipeline from start to finish.
activity_url =
This URL contains realm/domain and run ID information. This can be used to navigate directly
to a single run’s activities within a given domain (when authorized).
Example output =
https://team.pipelines.quickbase.com/activity/pipeline/efc4145d637f4ac09f1e7be6ed8ef499
triggered_at =
The ISO8601 timestamp for the date and time that an individual run of a Pipeline was
triggered. This is relative to UTC.
pipeline_id =
This is the numeric identifier corresponding to an individual Pipeline.
user_id =
The Pipelines user ID. The example below is specific to the Pipelines portion of the platform.
This output can be helpful when you request assistance from Tech Support.
pipeline_url =
This URL contains the realm/domain and Pipeline ID information. This can be used to
navigate directly to a Pipeline within a given domain (when authorized).
pipeline_name =
The user specified Pipeline name.
Use-cases
If you want to dynamically get the Pipeline ID in a custom alert message (rather than hardcoding a Pipeline ID in your alert) you could use the Runtime
metadata object to help.
Comments
For comments not included in the template output use {# your comment #} For example:
Variables
What attributes a variable has depends heavily on the application providing that variable.
Dot
You can use a dot ( . ) to access the attributes of a variable. The following examples do the same thing, a is an object with hello as a property:
{{ a.hello}}
{{ a['hello'] }}
{{a.get('hello')}}
For example, when you drag the variable from the popup menu, Pipelines uses variables with ( . ) operator
Custom Variables
Data Types
Boolean - represents the values true and false
Integer - Integers are whole numbers without a decimal part.
Floating point - numbers can be written using a ‘.’ as a decimal mark
Sequence [‘a’] everything between the two brackets is a list.
String -a sequence of characters, either as a literal constant or as some kind of variable
Tuple - can contain two values of different data types
Mappings - {'dict': 'of', 'key': 'and', 'value': 'pairs'}
Logic Conditions
IF
Example
LOOP
Example
{% for item in ['a', 'b', 'c']%}
{{ loop.index }} {{item}} “\n”
{% endfor %} output: 1 a \n 2 b \n 3 c \n
Example
{% if some_url %}
<found logic in html>
{% else %}
<Not found logic in html>
{% endif %}
Variable Description
loop.index
The current iteration of the loop. (1 indexed)
loop.index0
The current iteration of the loop. (0 indexed)
loop.revindex
The number of iterations from the end of the loop (1 indexed)
loop.revindex0
The number of iterations from the end of the loop (0 indexed)
loop.first
True if first iteration.
loop.last
True if last iteration.
loop.length
The number of items in the sequence.
loop.cycle
A helper function to cycle between a list of sequences. See the explanation below.
loop.depth
Indicates how deep in a recursive loop the rendering currently is. Starts at level 1
loop.depth0
Indicates how deep in a recursive loop the rendering currently is. Starts at level 0
loop.previtem
The item from the previous iteration of the loop. Undefined during the first iteration.
loop.nextitem
The item from the following iteration of the loop. Undefined during the last iteration.
loop.changed(*val)
True if previously called with a different value (or not called at all).
Loop Cycle
Filters
You can modify variables by using filters. Filters are separated from the variable by the pipe symbol ( | ) and may have optional arguments in
parentheses. Since multiple filters can be chained, the output of one filter is applied to the next. You can also filter like this for the entire block:
Term Definition
abs
Return the absolute value of the argument.
(x, /)
base64_encode (value) Encode a string using Base64 and return the encoded bytes.
base64_decode (value)
Decode the Base64 encoded string and return the decoded bytes.
Use the parameter output_encoding='binary' to select the format of the decoded output.
Outputs can be formatted as a string (default) or as bytes.
capitalize
(s) Capitalize a value. The first character is uppercase, all others lowercase.
default
If the value is undefined it will return the passed default value, otherwise the value of the variable:
(value, default_value='',
boolean=False)
{{ my_variable|default('my_variable is not defined') }}
{{ QB_VARIABLE | default(42) }}
Note: If the variable ‘QB_VARIABLE’ is not defined, the value used will be 42.
escape
Convert the characters &, <, >, ‘, and ” in strings to HTML-safe sequences. Use this if you need to display text that might contain suc
(s)
value as markup string.
first
(seq) Return the first item of a sequence.
float
(value, default=0.0) Convert the value into a floating point number. If the conversion doesn’t work it will return 0.0. You can override this default using th
For example, the float and int are just added like so: {{a.value|float}} and {{a.value|int}}. Replace would be {{a.value|replace("$","") for
without leaving a space.
format
Apply the given values to a printf-style format string, like string % values.
(value, *args, **kwargs)
From JSON
hmac
Use this filter to wrap sensitive data with a specific key and algorithm, so it can later be used for additional verification or authentica
int
Convert the value into an integer. If the conversion doesn’t work it will return 0. You can override this default using the first paramete
(value, default=0,
base (10) in the second parameter, which handles input with prefixes such as 0b, 0o and 0x for bases 2, 8 and 16 respectively. The b
base=10)
and non-string values.
For example, the float and int are just added like so: {{a.value|float}} and {{a.value|int}}. Replace would be {{a.value|replace("$","") for
without leaving a space.
join
Return a string which is the concatenation of the strings in the sequence. The separator between elements is an empty string per de
(value, d='',
optional parameter:
attribute=None)
length
(obj, /) Return the number of items in a container.
list
Convert the value into a list. If it was a string the returned list will be a list of characters.
(value)
lower
(s) Convert a value to lowercase.
map
Applies a filter on a sequence of objects or looks up an attribute
(*args, **kwargs)
{{ titles|map('lower')|join(', ') }}
max
Return the largest item from the sequence.
(value,
case_sensitive=False, {{ [1, 2, 3]|max }} output: 3
attribute=None) only in
the latest
md5
Returns MD5 hex-digest string generated from the text input.
(text)
Example usage:
{{ "some text" | md5 }}
output: 552e21cd4cd9918678e3c1a0df491bc3
min
(value, Return the smallest item from the sequence.
case_sensitive=False, {{ [1, 2, 3]|min }} output: 1
attribute=None)
only in the latest
random
Return a random item from the sequence.
(seq)
reject Filters a sequence of objects by applying a test to each object, and rejecting the objects with the test succeeding.
(*args, **kwargs)
If no test is specified, each object will be evaluated as a boolean.
Example usage:
{{ numbers|reject("odd") }}
replace
Return a copy of the value with all occurrences of a substring replaced with a new one. The first argument is the substring that shou
(s, old, new,
replacement string. If the optional third argument count is given, only the first count occurrences are replaced:
count=None)
{{ "Hello World"|replace("Hello", "Goodbye") }} output: Goodbye World
round
(value, precision=0, Round the number to a given precision. The first parameter specifies the precision (default is 0), the second the rounding method:
method='common') 'common' rounds either up or down
'ceil' always rounds up
'floor' always rounds down
If you don’t specify a method 'common' is used.
select
(*args, **kwargs) Filters a sequence of objects by applying a test to each object, and only selecting the objects with the test succeeding. If no test is s
evaluated as a boolean.
Example usage:
{{ numbers|select("odd") }}
{{ numbers|select("odd") }}
{{ numbers|select("divisibleby", 3) }}
{{ numbers|select("lessthan", 42) }}
{{ strings|select("equalto", "mystring")
sha1
Returns SHA1 hex-digest string generated from the text input.
(text)
Example usage:
Example usage:
sha256
Returns SHA256 hex-digest string generated from the text input.
(text)
Example usage:
sha384
(text) Returns SHA384 hex-digest string generated from the text input.
Example usage:
sha512
Returns SHA512 hex-digest string generated from the text input.
(text)
Example usage:
slice
Slice an iterator and return a list of lists containing those items. Useful if you want to create a div containing three ul tags that repre
(value, slices,
fill_with=None)
{%- for column in [1,2,3,4]|slice(2)%}
{{column}}
{%- endfor %}
output: [1, 2] [3, 4]
sort
(value, reverse=False, Sort an iterable
case_sensitive=False,
attribute=None) {%- for column in [4,2,3,4]|sort%}
{{column}}
{%- endfor %}
output: 2 3 4 4
string Make a string unicode if it isn’t already. In this way, a markup string will not be converted back to unicode.
(object)
striptags
(value) Strip SGML/XML tags and replace adjacent whitespace by one space.
sum
Returns the sum of a sequence of numbers plus the value of parameter ‘start’ (which defaults to 0). When the sequence is empty it
(iterable,
attribute=None, start=0) {{ [1,2,3]|sum }} output 6
Total: {{ items|sum(attribute='price') }}
timestamp_to_time
Converts UNIX timestamp to UTC Date Time format.
(value)
Example of usage:
title
Return a titlecased version of the value. This means that words start with uppercase letters, all remaining characters are lowercase
(s)
{{ "hello world" | title }} output: text:Hello World
tojson
Dumps the structure to JSON so that it’s safe to use in <script> tags. It accepts the same arguments and returns a JSON string. Not
(value, indent=None)
through the |tojson filter which will also mark the result as safe. Due to how this function escapes certain characters this is safe eve
only in the latest
The following characters are escaped in strings:
<
>
&
'
trim
Strip leading and trailing characters, by default whitespace.
(value, chars=None)
truncate
Return a truncated copy of the string.
(s, length=255,
killwords=False, end='...', {{ "foo bar baz qux"|truncate(9) }} output: foo...
leeway=None)
unique
(value, Returns a list of unique items from the given iterable.
case_sensitive=False, {{ ['hello', 'world', 'helloworld', 'HelloWorld']|unique|list }} output: ['hello', 'world', 'helloworld']
attribute=None)
only in the latest
upper
Convert a value to uppercase.
(s)
urlencode
(value) Quote data for use in a URL path or query using UTF-8.
wordcount
Count the words in that string.
(s)
{% if variable is defined %}
{{variable}}
{%else %}
UNDEFINED
{% endif %}
Boolean
Return true if the object is a boolean value
In In a sequence
Integer If an integer
Lt Less than
Ne Not equal
String
True
field {"foo":[1,2]}$ore
To_json(value, indent=None)
Dumps a structure to JSON so that it’s safe to use in <script> tags. It accepts the same arguments and returns a JSON string. Note that this is
available in templates through the |_ filter which will also mark the result as safe. Due to how this function escapes certain characters this is safe even
if used outside of <script> tags.
This makes it safe to embed such strings in any place in HTML with the notable exception of double-quoted attributes. In that case, you should single
quote your attributes or HTML escape it in addition.
You can use the indent parameter to enable pretty printing. Set it to the number of spaces that the structures should be indented with.
The easiest way to output a literal variable delimiter ( {{ ) is by using a variable expression:
{{ '{{' }}
{% raw %}
{% for item in seq %}
{{ item }}
{% endfor %}
{% endraw %}
Function Calls
You can use macros to avoid repeated tasks
Note: In our example $prev goes after the initial letter, so a. or b. etc.
To work with this behavior in a Jinja expression, we suggest you follow these guidelines:
Properties of objects in Jinja can be accessed either with the formats of {{a.my_field}} or through {{a['my_field']}} , which supports spaces
in the property name.
{{a.field_1 + a.field_2}}
Whether a search step returns a single record or many, it is returned as an array. If you use the for loop, it handles this for you. If not, you have to put in
the index you want to reference. So instead of using b.jan_enhancing you would use b[0].jan_enhancing if you know that your search step will
find results.
{{b.json.items}}
to this
b.json['items']
Jinja tips
Pipelines ignore fields with empty values in pipelines mapping, that is, it does not send them to the remote service, to avoid clearing a remote field
accidentally. This, however, is a problem when you want to explicitly clear this field in an Update pipe.
Solution: use template value {{CLEAR}} to clear a field, this is not bold in the rendered value.
Return to top
Return to top
Return to top
Related articles
API_DoQuery
© 2024 Quickbase. All Rights reserved. Quickbase is a registered trademark of Quickbase, Inc. Terms and conditions, features, support, pricing, and service options subject to
change without notice.