i have a Node which has a field node_field (entity reference revision) which points to a paragraph (can be added 3 times). That paragraph has only 1 field in it, which itself is a entity reference field that points to a node bundle.
I'm trying to loop through each paragraph and each node inside so i can render the entire node (not individual fields), i only want the nodes, don't need to render the paragraph.
Here's my approach in the node.twig.html via the content variable and it works, i get the desired result.
{% if content.my_field|render %}
{% for key, item in content.my_field if key|first != '#' %}
<div class="col-lg-4 col-md-6">
{{ item }}
</div>
{% endfor %}
{% endif %}
Now i want to do the exact same thing but use the node variable instead of content but i just can't seem to get it to print. Any ideas?
Realy it's depend of the content that you have into the item. If you have devel installed, you could use kint to see the difference between the content of both, the differents variables, etc...
Depends of the element where you are iterating you can render each elements, other times you need get the value of each item (item.getValue()[0]).
I hope that my answer could be enought.
Related
I have a custom twig template and within it I have a div that I only want to display if the value of another field on the page (weight) is -5.
I know how to show the field if there is a 'value' but im not sure how to write it for a specific value...?
What I have now:
{% if node.field_position_on_page.value %}
<div class="profile-pic">
{{ content.field_profile_picture }}
</div>
{% endif %}
I need it to be something like none.field_position_on_page[-5] but im not sure on the correct way to write that?
Using {% if node.field_position_on_page.value == -5 %} will compare the field to your specific value.
I need to check if anchor URL added from the CMS or not?
Actually didn't find any useful link yet, but I need help that I've created a Email widget and when I drag and drop that I need to add anchor if url added in the field from the Kentico Email CMS if didn't add anything in the anchor field it should not add anchor html.
Please help!
Thanks in Advance.
Here is the Anchor code in the widget:
<td>
Read More
</td>
{% if (Header_Circulation_Link == null) { %}
<div>Its null</div>
{% } else { %}
<div>its not null</div>
{% } %}
Equality checks support all available object types, with the following
special rules:
Empty strings are equal to null
See macro docs for more
Is there a way to check if a current page belongs to a collection? If so, can I check what’s the label of the collection?
Background story:
What I’m trying to achieve is to display a different layout for all pages that belong to a collection. With this new layout I want to display a side navigation (some sort of „See also”) with listing of all pages in the collection that the current site belongs to.
In case my question turns out to be dumb – forgive me, I’m new to jekyll and I really tried to find out the answer by myself.
page.collection returns the label of the collection to which the document belongs. So I guess you want to do something like:
{% if page.collection == 'COLLECTION_LABEL' %}
NEW LAYOUT
{% else %}
OLD LAYOUT
{% endif %}
To access the pages in a collection, you can use the label with site.COLLECTION_LABEL or site[COLLECTION_LABEL] (you need [] if it is a variable). Something like:
{% for page in site[page.collection] %}
{{ page.title }}
{% endfor %}
Any collection document has a page.collection variable which is the collection label.
But, if you want to associate a specific layout to a collection, you can use default configuration :
defaults:
-
scope:
type: mycollection
values:
layout: a_custom_layout
anyvar: a_custom_var
I have setup the following:
{% include '_elements/page-heading.html' with {'shortTitle': 'entry.shortTitle','title':'entry.title'} %}
However, when the page renders this template it is actually outputting "entry.shortTitle" in the page when it should surely actually know what the entry.title is for this page.
e.g. it should say "Latest News" not "entry.title".
Just wondering why this would be?
Thanks!
Enclosing entry.shortTitle with (single) quotes tells Twig that this simply is a string. When you want to pass the value of a variable, you have to leave away the quotes:
{% include '_elements/page-heading.html' with { 'shortTitle': entry.shortTitle, 'title': entry.title } %}
About the messaging framework, in the docs it is written that every message has a message.tag property that can be uses for css. so my code looks like this
try:
models.save()
message.success(request, "Model successfully saved")
except DatabaseManagementTransaction:
message.error(request, "Model could not be saved")
in my html template
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tag}} alert-dissmissable">
{{message}}
</div>
{%endfor%}
{% endif %}
But when the template is rendered i see no message.tag and the div class looks like this
<div class="alert alert- alert-dissmissable">...</div>
So do i have to create MESSAGE_TAGS in settings file for this to work? Why is the message.tag empty? And another question. What happens to messages after they are presented to user? Are they deleted? If i add a new model will the previous messages be shown to me plus the newly appended one?
If should be tags as alert-{{message.tags}} in the template.
What happens to messages after they are presented to user? Are they deleted?
Yes, they are cleared once iterated (or displayed through template) from the storage. Refer message expiry.
If i add a new model will the previous messages be shown to me plus the newly appended one?
The messages list will have all currently active messages. So if previous message is still there it will be shown as well.