In the Ansible Jinja Template, I have to Change the output charaktere
This works without any Letters
{{% endraw %} should eq {{ test_yml['php::settings']['PHP/max_execution_time'] }} {% raw %}}
Output Result = 60
{{% endraw %} should eq {{ test_yml['php::settings']['PHP/memory_limit'] }} {% raw %}}
Output Result = 16M, but I need this Result '16M' with the charaktere 'output'
I tested the following
[ {{'}} 'PHP/max_execution_time' {{'}} ]
[ (') 'PHP/max_execution_time' (') ] .....
Related
I am trying to work out a conditional iteration in Liquid. This is what i have
{% capture title_tag %}
{% for teacher in course.teachers %}
{% if course.teachers.size == 1 %}
{{course.title}} with {{ teacher.name | escape }}
{% elsif course.teachers.size > 1 %}
{{ course.title }} with {{ teacher.name }}
{% endif %}
{% endfor %}
{% endcapture %}
As expected, the first 'if' condition works well and i get an output like this
"Intro to Maths with Isaac Newton".
My problem is with the elsif, thus when the teacher size is greater than 1. I get this
"Intro to Maths with Isaac Newton Intro to Maths with Elon Musk".
What I actually want is
"Intro to Maths with Isaac Newton and Elon Musk"
I would appreciate any help. Thanks
The issue is you want the course.title to be printed not inside a loop.
{% capture title_tag %}
{{ course.title }} with ⇐ !!!! HERE
{% for teacher in course.teachers %}
{% if course.teachers.size == 1 %}
{{ teacher.name | escape }}
{% elsif course.teachers.size > 1 %}
{{ teacher.name }}
{% endif %}
{% endfor %}
{% endcapture %}
joining the names with and is more tricky and requires additional coding. Maybe you should just use String#join:
{% capture title_tag %}
{{ course.title }} with
{{ course.teachers.map { |t| t.name }.join(', ') }}
{% endcapture %}
I have exported a variable:
export myparam=one
I have template: file.tmpl :
myproptmpl =
{{ if eq .myparam "one" }}
{{ "one" }}
{{ else }}
{{ "something else" }}
{{ end }}
And when I run confd I get:
# /usr/bin/confd -onetime -backend env
2016-04-20T15:21:58Z 8faae31d53a1 /usr/bin/confd[91]: ERROR template: file.tmpl:70:6: executing "file.tmpl" at <eq .myparam "one">: error calling eq: invalid type for comparison
I'm a newbie on confd. How can I compare an OS environment variable to values and based on them generate different resulting output file out of template?
You need get the variable first and after that then you can compare.
Ex.:
myproptmpl =
{{ if eq (getv .myparam) "one" }}
{{ "one" }}
{{ else }}
{{ "something else" }}
{{ end }}
How can I change the default language in Jekyll? I would like, to have German names for the days using the {{ … | date "%A" }} filter.
From Jekyll Date Formatting Examples by Alan Smith
_includes/date-ge.html
<!-- Whitespace added for readability -->
{% assign m = include.date | date: "%-m" %}
{{ include.date | date: "%-d" }}
{% case m %}
{% when '1' %}Januar
{% when '2' %}Februar
{% when '3' %}März
{% when '4' %}April
{% when '5' %}Mai
{% when '6' %}Juni
{% when '7' %}Juli
{% when '8' %}August
{% when '9' %}September
{% when '10' %}Oktober
{% when '11' %}November
{% when '12' %}Dezember
{% endcase %}
{{ include.date | date: "%Y" }}
Now instead of page.date or post.date you can call this include and pass it date as an argument.
{% include date-ge.html date=page.date %}
For me the i18n_filter plug-in together with the localization of choice from rails-i18n in _locales did the trick.
The filter is used by simply writing e.g.
{{ post.date | localize: "%A, %-d.%m.%Y %k.%M Uhr" }}
I have the following string ("my_str") in a Shopify metafield:
a:3,b:1,c:2,d:2,e:2,f:2
The keys are product variant IDs (shortened to a, b, c...) and the numbers are quantities.
I need to parse it into key:value pairs so I can do something like this with it:
{% assign my_str = collection.metafields.local.my_metafield %}
{% assign my_map = my_str | parse ???? %}
{% for product in collection.products %}
{% assign temp_qty = 1 %}
{% for pair in my_map %}
{% if pair[0] == product.variants.first.id %}
{% assign temp_qty = pair[1] %}
{% endif %}
{% endfor %}
<input type="hidden" id="abc-{{ forloop.index0 }}" value=temp_qty />
{% endfor %}
I definitely don't know how to parse my_str. I'm also open to suggestions about the best approach overall.
Liquid is pretty limited when it comes to creating arrays. The common approach is to use the split string filter.
In your case, it would look something like this:
{% assign my_str = 'a:3,b:1,c:2,d:2,e:2,f:2' %}
{% assign my_arr = my_str | split: ',' %}
{% for pair_str in my_arr %}
{% assign pair_arr = pair_str | split: ':' %}
ID: {{ pair_arr[0] }} Qty: {{ pair_arr[1] }} <br />
{% endfor %}
This blog post is also an interesting read on the topic of Liquid arrays: Advanced Arrays in Shopify's Liquid
Is it possible to iterate through the Shopify linklists?
Currently I'm doing this to print all the items in all the menus:
{% assign menuHandles = "menu-1-handle|menu-2-handle|menu-3-handle" | split: "|" %}
{% for list in menuHandles %}
{% for link in linklists[list].links %}
{{ link.title }}
{% endfor %}
{% endfor %}
This requires hard coding the menu names and i'd like to avoid that.
This has now been added! Fast turnaround. :D
{% for linklist in linklists %}
{{ linklist.handle }}
{% endfor %}