Forum Discussion
DougHenning1
3 years agoCommunity Manager
Hi @Prashant Maheshwari glad to help! I'm not sure why using
Do you do all your Jinja testing in Pipelines? I like to use an online Jinja parser like this one (https://j2live.ttl255.com) to test since it's quicker than running Pipelines after each change. Let's try it out and test the code!
1. Put the Jinja code in the Template box:
2. Create a sample record structure in the Data input box. This simulates a Pipeline step A so data can be referenced as {{a.id}}:
3. Click the [Render Template] button and you should get the results in Rendered Template box:
NOTE: The online parsers don't support all the filters that Pipelines provides (e.g. time) but can help with most Jinja.
Regarding {% if not loop.last %},{% endif %} vs {{ ',' if not loop.last }}, both are certainly acceptable. I tend to prefer the second for easy statements and the first for more involved if/then/else cases, but use whatever works best for you!
Hope that's helpful!
------------------------------
Doug Henning
------------------------------
{{x}}
isn't working for you. That's standard Jinja, so maybe something else is causing the issue?Do you do all your Jinja testing in Pipelines? I like to use an online Jinja parser like this one (https://j2live.ttl255.com) to test since it's quicker than running Pipelines after each change. Let's try it out and test the code!
1. Put the Jinja code in the Template box:
{%- set plist = a.quick_capture.split('\n') -%}
{
"to": "br8hpcpk7",
"data": [
{%- for x in plist if x|trim != '' %}
{
"18": { "value": "{{a.related_director}}" },
"89": { "value": "{{a.id}}" },
"6": { "value": "{{loop.index}} {{ x|trim }}" }
}{{ ',' if not loop.last }}
{%- endfor %}
]
}
2. Create a sample record structure in the Data input box. This simulates a Pipeline step A so data can be referenced as {{a.id}}:
{
"a": {
"quick_capture": "testing\none\n\ntwo\nthree",
"id": 12345,
"related_director": "bob testing"
}
}
3. Click the [Render Template] button and you should get the results in Rendered Template box:
NOTE: The online parsers don't support all the filters that Pipelines provides (e.g. time) but can help with most Jinja.
Regarding {% if not loop.last %},{% endif %} vs {{ ',' if not loop.last }}, both are certainly acceptable. I tend to prefer the second for easy statements and the first for more involved if/then/else cases, but use whatever works best for you!
Hope that's helpful!
------------------------------
Doug Henning
------------------------------
PrashantMaheshw
3 years agoQrew Captain
HI Doug,
Thanks for the site , I was indeed checking all permutations of code on pipeline page directly. This seems wicked fast .
I'm running into an error when I copy paste the code and data in rendered template output
------------------------------
Prashant Maheshwari
------------------------------
Thanks for the site , I was indeed checking all permutations of code on pipeline page directly. This seems wicked fast .
I'm running into an error when I copy paste the code and data in rendered template output
Data error:
expected '<document start>', but found '<scalar>'
in "<unicode string>", line 7, column 2:
}
^
------------------------------
Prashant Maheshwari
------------------------------
- DougHenning13 years agoCommunity ManagerSorry about that, I don't know where that extra character came from. I just updated the post so you can recopy it without the error.
Once you get used to testing like this you'll really appreciate how fast it can be!
------------------------------
Doug Henning
------------------------------