Jekyll – Check if page belongs to a collection - collections

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

Related

Drupal 8 Twig looping through a paragraph EntityRevisionItemList

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.

How can i add "if condition" around the anchor to check the field value empty or not?

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

How to set page title in OroCrm (Symfony2) with Twig

I'm a new in OroCRM and Symfony2. I'm trying to code a page that retrieves all record of a table. But I don't know how to change title of this page, it always displays it's url (http://localhost/crm-application/web/app_dev.php/...).
This is my twig file:
{#index.html.twig#}
{% extends 'OroUIBundle:actions:index.html.twig' %}
{% import 'OroUIBundle::macros.html.twig' as UI %}
{% set gridName = 'b2b-customers-grid' %}
{% set pageTitle = 'B2B Customers' %}
I have tried many way but i could not make it. I usually get that error:
A template that extends another one cannot have a body”
Any help? Thanks a lot. :)
pageTitle is not that title that you think of, as I understand you want to set title for the whole page, browser window title, head > title in html, and pageTitle variable it's for content header title.
Do you have any other content in your index.html.twig? That could be the reason you got an error.
To set window title, you should use navigation.yml in your bundle's Resources/config with something like
oro_titles:
orocrm_account_index: ~
or
oro_titles:
orocrm_account_index: 'Create Account'
Don't forget to clear cache after that, if you had no this file before and run app/console oro:navigation:init to reload titles configuration

Variables are being ignored using the Twig Include template tag

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 } %}

symfony2: how to check if form is new?

I want to check if a form is new in my template, something like $form->isNew() in symfony 1.4, but i did not find a solution.
Currently, i'm using this technique:
{% null != entity.getId %}
it works, but are there other solutions which are more clean?
I use this:
{% if form.vars.submitted == false %}DO WHATEVER HERE{% endif %}
More info in form functions and variables here:
https://symfony.com/doc/current/reference/forms/twig_reference.html
Symfony2 forms are less coupled to the model than symfony1 forms. Form in Symfony2 cannot be "new" or "old". It's the entity which is persisted, not the form. Forms job is to put submitted data to the model object.
Remember that model class doesn't have to be a doctrine entity (can be really an object of any class). It's up to you to define what does it mean that object is new or not (persisted or not). Again, it's not a form which is persisted.
Btw, you could check for id like this:
{% if entity.id %}{% endif %}
A better solution nowadays (SF3) will be:
{% if form.vars.data.id %}{% endif %}

Resources