I have an array that I use to create a table, however, I first need to identify the path.
my Array is saved in:
page.cart.lineitems.elements
this is the output if i dump it:
in these two keys are my table arrays but I can't get inside.
The keys are named after 2 items in a cart where I can identify which one I want to use, so I get the values from a key called:
im saving the value of "_key" here:
{% set articleKey = _key %}
so now I should be able to use the key name as such
page.cart.lineitems.elements.articleKey
instead of page.cart.lineitems.elements.120ac316d177487fa879c51e02845135
inside the articleKey.extensions.TwpSortiment.data is
so I wrote this code but it still doesn't go inside my "articleKey"
<div class="twp-sortiment-form">
{% set articleKey = _key %}
{% for key in page.cart.lineitems.elements.articleKey.extentions.TwpSortiment.data %}
//my table code
{% endfor %}
</div>
whats is the issue? why can I not go inside the articleKey? I tried it even with writing the whole name but an error occurs:
Unexpected token "name" of value "ac316d177487fa879c51e02845135" ("end of statement block" expected).
fixed it by typing the path this way page.cart.lineitems.elements[articleKey]
Related
I'm very new in go templates and honestly I did not understand yet some of the main logic of it, therefore I hope you can turn me into the right direction.
I have a simple JSON for the test (in fact this is the JSON-ized output of a Grafana alerting):
{
"_15_min_reduced": 1.3122222222222208,
"_1_min_reduced": 1.7260000000000002,
"alert": 0,
"cpu_cores_reduced": 4
}
How can I show a 'message' based on go templates only in case of 1 value of the alert key?
My basic misunderstanding is somewhere here:
{{ . }} shows me the whole map of the JSON node, it's fine.
{{ range . }}
{{ . }}
{{ end }}
shows me all the values of the keys as a sequence, but not the keys themselves.
{{ .alert }} shows me the value of the 'alert' key (in our sample case is 0).
But...
{{ if eq .alert 1 }}
There are problems...
{{ end }}
...gives me an 'error'. Seems I can not refer in such was to the defined key, and its value, what is a bit confusing me, as when I directly 'ask' for its value I get the correct result.
Please help me, what is the point where I lost in the go template structure/syntax?!
Lot of thanks for it...
It was a hard run, what I already thought and saw in at firt time, but cound not confirm and verify...
{{ printf "%T" .alert }} shows me that the type of the key is 'float64', what is really incomparable with an 'int' zero. So with a little 'trick'...
{{ if eq .alert 1.0 }}
There are problems...
{{ end }}
...is already working as in this case 1.0 is a comparable 'float' format.
I tried to convert the value of the .alert to 'int' lot of times/methods but sadly at last unsuccesfully, this is why I slipped into the hole... :(
Really basics, really lame, really my bad, but I hope it could help to anyone in the future...
----- UPDATE #1 ----
Sadly while this final syntax is fine, Grafana still can not accept it so from now I leave it alone :(
I’m about to integrate a Santander widget on my Shopify site, but I need to replace data-amount with price variable: https://www.dropbox.com/s/cf025mnb5lr8j9m/satander_widget.jpg?dl=0
I have tried to use data-amount="{{current_variant.price}}"> but nofthing happens.
https://www.dropbox.com/s/oibwr7qrb20xk33/27.06.2022_19.32.43_REC.png?dl=0
Any idea why it do not works? I'm using current_variant.price others places on the product page
current_variant is not a default variable of Shopify. It is something that typicall the theme is setting, somewhere.
You just need to be sure that you're inside the scope of that variable.
Search for current_variant = and you will find where is set, normally this is the value
{%- assign current_variant = product.selected_or_first_available_variant -%}
I am trying to retrieve a metafield with all_products[] but using a locale json file content as the handle.
I have created this value in the en.default.json. If I just use {{'products.product.product_handle' | t}} I receive the proper handle so I know that I'm getting the right information but for whatever reason I can't pass that value into the all_products[] function.
I've tried the following code:
{{all_products[ 'products.product.product_handle' | t ].metafields.my_fields.cardtext}}
and
{% assign text = 'products.product.product_handle' | t %}
{{all_products[text]..metafields.my_fields.cardtext}}
Json Setup:
"product_handle": "{{ handle }}"
Can anyone tell me what I'm missing or if there is another way to display this content?
The first syntax is invalid.
The second syntax is almost valid, you have double dots before metafields => ..metafields
So when you fix the above as long as you are targeting the correct translatable string and metafield it should work:
{% assign text = 'products.product.product_handle' | t %}
{{all_products[text].metafields.my_fields.cardtext}}
You can check if you are getting the product first, for example:
{{all_products[text].id}}
If you are getting the product but not the metafield, then the issue might be in the metafield target.
I'm trying to display the data stored in a variable into a form field. The variable programme_title definitely holds the data as I have tested it through other methods.
However, when I use the following, the entry form field simply reads "programme_title". How can I get the data from the variable to fill the field?
<div> Item 1 <input name=item_description-0-item value=programme_title>
</div>
I assume from the "jinja2" tag you're using jinja2 templates, where variables/expressions are placed in {{ }}:
<input name="item_description-0-item" value="{{ programme_title }}">
If it's just HTML + JavaScript then set the value property of the input element, for example by this JavaScript expression:
document.querySelector('[name="item_description-0-item"]').value = 'programme_title';
I have a scenario where I should display an image when a value of one field of a table is present in another table. I'm not sure how this condition can be done. Can anybody help? In html or even in angularjs. For better understanding, my code in html and what I'm trying to do,
html:
{% if {{vio.pdb_pid}} }
{% if is_secure_device == 'true'%}
{% verbatim %}
<img class="img-rounded" ng-src="{{vio.pdb_pattern_img}}">
{% endverbatim %}
Model which has {{vio.pdb_pid}} value:
class OrcPattern(models.Model):
pdb_id = models.IntegerField(null=True, blank=True)
Model of the other table:
class SiverifyVerificationSite(models.Model):
pattern_id = models.IntegerField(null=True, blank=True)
My first line in the code.i.e. the if statement is incomplete. the value {{vio.pdb_pid}} should be checked on a table called sivorcdds(the field name in this table is pdb). Precisely, if {{vio.pdb_pid}} exists in pattern_id.SiverifyVerificationSite(fieldname.tablename)` I should display an image as like in my code. I don't know how to do this. I'm new to coding. Any help would be appreciated.
Note: The two models are of different applications.