You can use the functions written in the source code like this. Of course, not all of them can be used, and generally public 関数名only functions like the ones below can be used.
addAllThere is also an unpublished function in this source code called , which combines an array with another array and has two ways of using it.
A. addAll(挿入位置, 配列)
B. addAll(配列)
Plain text
Now, let's try adding [3,4,5] after the 1 (second position) in [0,1,2] using method A.
{% set numbers = [0,1,2] %}
{% do numbers.addAll(2, [3,4,5]) %}
{{ numbers }}
HTML + HubL
The result [0, 1, 3, 4, 5, 2]is .
Of course, you can create it using for without using the addAll function.
{% set numbers = [0,1,2] %}
{% for n in [3,4,5] %}
{% do numbers.insert(loop.index + 1, n) %}
{% endfor %}
{{ numbers }}
HTML + HubL
What do you think? The addAll function is more readable than the for function. There are
other useful functions for manipulating associative arrays .put
SizeLimitingPyMap.java
https://github.com/HubSpot/jinjava/blob ... p.java#L34
updateThe put function allows you to dynamically add keys to an associative array. You can see the difference by comparing it with similar functions .
{% set newkey = "KEY_NAME" -%}
{% set dict_var = {"authorName": "Douglas Judy", "authorTitle": "Mastermind" } %}
{# 連想配列のキーに変数newkeyを使用したいけれどそのまま文字として入る #}
{% do dict_var.update({newkey: "Jake"}) %}
{# 連想配列のキーに変数newkeyの値が使用される #}
{% do dict_var.put(newkey, "Mike") %}
{{ dict_var }}
{# 結果
{
authorName=Douglas Judy,
authorTitle=Mastermind,
newkey=Jake,
KEY_NAME=Mike
}
#}
HTML + HubL
Conclusion
As mentioned above, this is not officially documented and may be subject to change. I don't know
where this will be useful, but this is an introduction to how to check for private functions.
Editor in Chief, Access Site
Editor in Chief, Access Site
We post useful information related to Marketing DX and Sales DX.
We also post information on the following india number data official SNS accounts, so please follow us!
Visit our Facebook page
X View Post
Visit our LinkedIn page
Visit our YouTube page
Facebook
Twitter
LinkedIn
Note
Hatena Blog
Previous article
Back to blog list
Next Article
Popular articles
2023.01.28
Build a sample serverless function in HubSpot
How to implement an efficient for loop by specifying the range of an array in HubL
2022.8.15
Did you find the add function in the source?
-
- Posts: 375
- Joined: Tue Jan 07, 2025 4:26 am