I want to get hold of the value of DashboardCalc, which lies in the following array:
array(1) {
[0]=>
object(MatrixSubHeadline)#27226 (4) {
["schemaHeadline":"MatrixSubHeadline":private]=>
object(common_db_schemacontent)#28107 (12) {
["viewhelp":"common_db_schemacontent":private]=>
NULL
["unsavedTranslations"]=>
array(0) {
}
["objectLangCode":"common_translation_translateobject":private]=>
string(0) ""
["transUseFallback":"common_translation_translateobject":private]=>
bool(true)
["classData":protected]=>
array(15) {
["SchemaContentID"]=>
string(5) "15611"
["SchemaID"]=>
string(3) "132"
["IndexNo"]=>
string(1) "0"
["PageNo"]=>
string(1) "7"
["ContentType"]=>
string(8) "headline"
["QuestionID"]=>
string(1) "0"
["HeadlineContentID"]=>
string(1) "0"
["ImagePath"]=>
string(0) ""
["ThumbPath"]=>
string(0) ""
["Text"]=>
string(21) "Generelle kommentarer"
["ContentSettings"]=>
string(2) "[]"
["CreatedUserID"]=>
string(2) "15"
["CreatedTime"]=>
string(19) "2021-11-11 12:36:00"
["UpdatedUserID"]=>
string(2) "15"
["UpdatedTime"]=>
string(19) "2021-12-17 15:35:00"
}
["classChanges":protected]=>
array(0) {
}
["tableName":protected]=>
string(13) "schemacontent"
["primaryIDName":protected]=>
string(15) "SchemaContentID"
["cacheEnabled":protected]=>
bool(true)
["accountTable":protected]=>
bool(false)
["extraData":protected]=>
array(0) {
}
["saveError":"common_library_dbbase":private]=>
bool(false)
}
["questionList":"MatrixSubHeadline":private]=>
array(1) {
[0]=>
object(MatrixQuestion)#27225 (4) {
["content":"MatrixQuestion":private]=>
object(common_db_schemacontent)#28106 (12) {
["viewhelp":"common_db_schemacontent":private]=>
NULL
["unsavedTranslations"]=>
array(0) {
}
["objectLangCode":"common_translation_translateobject":private]=>
string(0) ""
["transUseFallback":"common_translation_translateobject":private]=>
bool(true)
["classData":protected]=>
array(15) {
["SchemaContentID"]=>
string(5) "15612"
["SchemaID"]=>
string(3) "132"
["IndexNo"]=>
string(1) "1"
["PageNo"]=>
string(1) "7"
["ContentType"]=>
string(8) "question"
["QuestionID"]=>
string(3) "923"
["HeadlineContentID"]=>
string(5) "15611"
["ImagePath"]=>
string(0) ""
["ThumbPath"]=>
string(0) ""
["Text"]=>
string(0) ""
["ContentSettings"]=>
string(21) "{"criteriaenabled":0}"
["CreatedUserID"]=>
string(2) "15"
["CreatedTime"]=>
string(19) "2021-11-11 12:36:00"
["UpdatedUserID"]=>
string(2) "15"
["UpdatedTime"]=>
string(19) "2021-12-17 15:35:00"
}
["classChanges":protected]=>
array(0) {
}
["tableName":protected]=>
string(13) "schemacontent"
["primaryIDName":protected]=>
string(15) "SchemaContentID"
["cacheEnabled":protected]=>
bool(true)
["accountTable":protected]=>
bool(false)
["extraData":protected]=>
array(0) {
}
["saveError":"common_library_dbbase":private]=>
bool(false)
}
["question":"MatrixQuestion":private]=>
object(common_db_question)#27289 (13) {
["schemaUsage":"common_db_question":private]=>
NULL
["viewHelper":"common_db_question":private]=>
NULL
["unsavedTranslations"]=>
array(0) {
}
["objectLangCode":"common_translation_translateobject":private]=>
string(0) ""
["transUseFallback":"common_translation_translateobject":private]=>
bool(true)
["classData":protected]=>
array(23) {
["QuestionID"]=>
string(3) "923"
["OwnerAccountID"]=>
string(1) "0"
["Question"]=>
string(21) "Generelle kommentarer"
["QuestionType"]=>
string(1) "5"
["Answers"]=>
string(178) "{"answers":null,"groupanswers":[{"count":"1","text":"Ja, jeg vil gerne tilf\u00f8je en generel kommentar","index":"0"}],"questions":["Har du andre kommentarer til din trivsel?"]}"
["SubText"]=>
string(59) "(Skriv dine kommentarer ved at trykke på kommentar-ikonet)"
["AllowOther"]=>
string(1) "0"
["MixAnswers"]=>
string(1) "0"
["MustAnswer"]=>
string(1) "0"
["MinAnswers"]=>
string(1) "0"
["MaxAnswers"]=>
string(1) "0"
["Columns"]=>
string(1) "1"
["OtherText"]=>
string(0) ""
["CreatedUserID"]=>
string(2) "15"
["CreatedTime"]=>
string(19) "2021-11-11 12:36:00"
["UpdatedUserID"]=>
string(2) "15"
["UpdatedTime"]=>
string(19) "2021-11-11 12:44:00"
["DashboardShow"]=>
string(1) "0"
["DashboardCalc"]=>
string(1) "0"
["QuestionTags"]=>
string(1) "0"
["UseComment"]=>
string(1) "1"
["IsPublic"]=>
string(1) "0"
["StdAnswer"]=>
string(1) "0"
}
["classChanges":protected]=>
array(0) {
}
["tableName":protected]=>
string(8) "question"
["primaryIDName":protected]=>
string(10) "QuestionID"
["cacheEnabled":protected]=>
bool(true)
["accountTable":protected]=>
bool(false)
["extraData":protected]=>
array(0) {
}
["saveError":"common_library_dbbase":private]=>
bool(false)
}
["text":"MatrixQuestion":private]=>
string(41) "Har du andre kommentarer til din trivsel?"
["index":"MatrixQuestion":private]=>
int(0)
}
}
["questionMap":"MatrixSubHeadline":private]=>
array(1) {
[15612]=>
array(1) {
[0]=>
int(0)
}
}
["useComments":"MatrixSubHeadline":private]=>
bool(true)
}
}
Please note: the array contains a few objects, which are private. I am not sure whether private objects can be accessed or not, or if the "private" is about the name, or the content.
The data is inherited from a database.
You can access object value by using loop iteration like this:
I am selecting here SchemaContentID, SchemaID and IndexNo.
{% for arrayObj in Objs %}
<ul>
<li>{{ Objs.SchemaContentID}}</li>
<li>{{ Objs.SchemaID}}</li>
<li>{{ Objs.IndexNo}}</li>
</ul>
{% endfor %}
I have in my ansible playbook a dict that looks similar to:
"fact_one": true,
"fact_two": true,
"disks": [
{
"name": "/dev/sda"
},
{
"name": "/dev/sdb"
},
{
"name": "/dev/sdc"
}
],
}
So, now i need to do a loop through the disks items and then update each disks entry with a new variable called ID. So, my new dict should looks like:
"fact_two": true,
"disks": [
{
"name": "/dev/sda"
"id": "id001"
},
{
"name": "/dev/sdb"
"id": "id002"
},
{
"name": "/dev/sdc"
"id": "id003"
}
],
}
Also, as you can see, my ID is a counter that should be added in +1 each iteration.
How I can write this kind of loop in Ansible ?
I want to update the existing facts and not to create new ones.
One solution is this one:
set_fact:
disks: |
{% set result = [] %}
{% for d in disks %}
{% set _ = result.append('name': d.name, 'id': 'id00' + loop.index | str) %}
{% endfor %}
{{ result }}
or
set_fact:
disks: |
{% set result = [] %}
{% for d in disks %}
{% set item = d %}
{% set _ = item.update('id': 'id00' + loop.index) | str ) %}
{% set _ = result.append(item) %}
{% endfor %}
{{ result }}
I'm currently working with woocommerce using timber plugin that provides a twig template engine. Right now I'm trying to access a value that is within a nested array ["sizes"]. How do I fetch the value 400ml from inside the "[sizes]" array.
["_product_attributes"]=>
array(2) {
["sizes"]=>
array(6) {
["name"]=>
string(5) "Sizes"
["value"]=>
string(5) "400ml"
["position"]=>
string(1) "0"
["is_visible"]=>
string(1) "1"
["is_variation"]=>
string(1) "0"
["is_taxonomy"]=>
string(1) "0"
}
["color"]=>
array(6) {
["name"]=>
string(5) "Color"
["value"]=>
string(3) "Red"
["position"]=>
string(1) "1"
["is_visible"]=>
string(1) "1"
["is_variation"]=>
string(1) "0"
["is_taxonomy"]=>
string(1) "0"
}
}
I tried the snippet below but it only returns empty
{% for attr in post._product_attributes.sizes.value %}
{{ attr }}
{% endfor %}
The snippet below returns NULL
{% for attr in post._product_attributes.sizes %}
<pre>
{{ dump(attr.value) }}
</pre>
{% endfor %}
I am a complete newcomer to Liquid, started playing with it a few hours ago.
i am trying to parse a JSON and extract certain key value pairs out of it, yet i am not successful at all. the JSON is outputed from Azure Form Recognizer, and i am trying to do a Liquid json 2 json in Logic Apps.
the JSON looks like this
{
"status": "success",
"pages": [
{
"number": 1,
"keyValuePairs": [
{
"key": [
{
"text": "Page No:",
"boundingBox": [
507.4
]
}
],
"value": [
{
"text": "1",
"boundingBox": [
586.8
],
"confidence": 1.0
}
]
},
....
...
what i am looking for is to loop through the keyValuePairs array, and then pull the "text" element from the "key" array, and the "text"+"confidence" element from the "value"array.
Could you please help me in understanding the approach here? I tried something like this, but the array comes back empty
{
"results":[
{% for kvp in content.keyValuePairs %}
{% for mykey in kvp.key %}
"thiskey":"{{mykey.text}}
{%- endfor -%}
{% for myval in kvp.value %}
"thisvalue":{{myval.text}}
"thisconfidence":{{myval.confidence}}
{%- endfor -%}
{%- endfor -%}
]
}
And second question: what's the best approach for debugging Liquid, so i can see where i am getting it wrong and adjust?
Thank you!
According to the sample of json data and the liquid template you provided, I know there are more than one object under the property keyValuePairs in your json data. So I think using "Parse JSON" action is not a good solution for it, we'd better use liquid template as you mentioned in your question. But I'm confused about that if there are more than one object under the property pages in your json data ?
Now I assume the json data just has one object under the property pages and provide the solution of liquid template for your reference (If the json data has more than one object under the property pages, please provide some more details of your requirements and I will modify my solution).
I assume your json data like below:
{
"status": "success",
"pages": [
{
"number": 1,
"keyValuePairs": [
{
"key": [
{
"text": "Page No:",
"boundingBox": [
507.4
]
}
],
"value": [
{
"text": "1",
"boundingBox": [
586.8
],
"confidence": 1.0
}
]
},
{
"key": [
{
"text": "Page No:",
"boundingBox": [
507.4
]
}
],
"value": [
{
"text": "2",
"boundingBox": [
586.8
],
"confidence": 2.0
}
]
}
]
}
]
}
1. We need to get the object under the property pages and put it in the "content" of "Transform JSON to JSON" action. We can parse the whole json data(with "Parse JSON" action) first and do something like below:
2. Upload the liquid template to integration account, please refer to my liquid template:
{
"results":[
{% for kvp in content.keyValuePairs %}
{%- if forloop.Last == true -%}
{
{% for mykey in kvp.key %}
"thiskey": "{{mykey.text}}",
{%- endfor -%}
{% for myval in kvp.value %}
"thisvalue": "{{myval.text}}",
"thisconfidence": "{{myval.confidence}}"
{%- endfor -%}
}
{%- else -%}
{
{% for mykey in kvp.key %}
"thiskey": "{{mykey.text}}",
{%- endfor -%}
{% for myval in kvp.value %}
"thisvalue": "{{myval.text}}",
"thisconfidence": "{{myval.confidence}}"
{%- endfor -%}
},
{%- endif -%}
{%- endfor -%}
]
}
3. After running this logic, we can get the result as:
{
"results": [
{
"thiskey": "Page No:",
"thisvalue": "1",
"thisconfidence": "1"
},
{
"thiskey": "Page No:",
"thisvalue": "2",
"thisconfidence": "2"
}
]
}
Something you need to be aware of:
Since we put the object under the property pages to the content of "Transform JSON to JSON" action, so the content in the liquid template represents it.
In liquid template, we need to be careful about the comma character, so I use {%- if forloop.Last == true -%} to judge if it is the last object in the loop, and then judge if we need to add the comma character.
For your second question about what's the best approach for debugging Liquid ?, unfortunately I think we can just complete the liquid template and upload to the integration account, then we can see the result. I don't know if there is a way for us to debug it easily.
Hope it helps~
I have tried to design workflow using your sample JSON payload.
I have parsed the JSON schema and extracted the required values from it.
Since your JSON payload is a bit complex, we need to use Logic App Expressions to extract the value out of it.
Payload I used:
{
"status": "success",
"pages": [{
"number": 1,
"keyValuePairs": [{
"key": [{
"text": "Page No:",
"boundingBox": [
507.4
]
}],
"value": [{
"text": "1",
"boundingBox": [
586.8
],
"confidence": 1.0
}]
},
"null"
]
}]
}
Once you get the JSON output from the upstream actions, you have to parse it.
Now, Initialize a couple of variables to get the required value from the parsed JSON.
Expression to be used in the first variable: concat(body('Parse_JSON')?['pages'][0]?['keyValuePairs'][0]?['key'][0]?['text'],body('Parse_JSON')?['pages'][0]?['keyValuePairs'][0]?['value'][0]?['text'])
Expression to be used in the second variable: body('Parse_JSON')?['pages'][0]?['keyValuePairs'][0]?['value'][0]?['confidence']
Finally, the logic apps after your Form Recognizor will look something like this:
I hope it helps!
I need to output following array
object(stdClass)#6 (14) { ["subcategories"]=>
array(9) { [0]=> object(stdClass)#31 (13) { ["id"]=> string(2) "10"
["parent_id"]=> string(1) "6" ["name"]=> string(8) "Soup" ["description"]=> string(0) "" ["url"]=> string(4) "supy" ["meta_title"]=> string(8) "Soup" ["meta_keywords"]=> string(8) "Soup" ["meta_description"]=> string(0) "" ["image"]=> string(0) "" ["visible"]=> string(1) "1" ["position"]=> string(1) "7" ["path"]=> array(2) { [0]=> RECURSION [1]=> RECURSION } ["children"]=> array(1) { [0]=> int(10) } } [1]=> object(stdClass)#32 (13) { ["id"]=> string(2) "11" ["parent_id"]=> string(1) "6" ["name"]=> string(12) "Сашими" ["description"]=> string(0) "" ["url"]=> string(7) "sashimi" ["meta_title"]=> string(12) "Сашими" ["meta_keywords"]=> string(12) "Сашими" ["children"]=> array(1) { [0]=> int(10) } } [1]=> object(stdClass)#32 (13) { ["id"]=> string(2) "11" ["parent_id"]=> string(1) "6" ["name"]=> string(12) "Сашими" ["description"]=> string(0) "" ["url"]=> string(7) "sashimi" ["meta_title"]=> string(12) "Сашими" ["meta_keywords"]=> string(12) "Сашими" ["meta_description"]=> string(0) "" ["image"]=> string(0) "" ["visible"]=> string(1) "1" ["position"]=> string(1) "8" ["path"]=> array(2) { [0]=> RECURSION [1]=> RECURSION }
i think that here is multiple foreach need for output each ["name"] from ["subcategories"]
Now i've the following code
{foreach name=cats from=$category->name item=n}
<li>
<a href="catalog/{$n->url}" category_id="{$n->id}">
<b>{$n}</b>
</a>
</li>
{/foreach}
which displays only one Name of the current category (Soup).
How can i output each ["name"] from ["subcategories"] ?
As you said, you need a foreach for every level:
{foreach name=cats from=$category->name item=n}
<li>
<a href="catalog/{$n->url}" category_id="{$n->id}">
<b>{$n}</b>
</a>
{foreach name=subcats from=$n.subcategories item=s}
....
{/foreach}
</li>
{/foreach}
or maybe is from=$n->subcategories, I'm not sure, as you put all the array in a single line and it's difficult to see it