translate english keyword to arabic in template file inside table with use of po file.not translating.translation is included in po file - translate

tried this: added the text to po file. not translating
{% load i18n %}
{% trans "Thanks you," %}
{% trans "The Team Auraa" %}

Related

RainLab.Blog Post List: List Sub-Categories under a specific Top-Level Category

I'm working on an October CMS project which use a blog where I need to seperate blog posts in two major categories. When listing blog posts using the RainLab.Blog plugin's Post List component, I need to list categories that are sub-categories under a specific top-level category and exclude other categories.
In the TWIG template, I want to iterate through and list out the categories that belong to "Birds" and not "Sealife".
In the default Post List component, categories are listed like this:
{% for category in post.categories %}
{{ category.name }}{% if not loop.last %}, {% endif %}
{% endfor %}
I would like to change this to something like this:
{% for category in post.categories %}
{# if category is a sub-category of "Birds"... #}
{{ category.name }}{% if not loop.last %}, {% endif %}
{# endif #}
{% endfor %}
So I would like the post to be listed as "Shorebirds" and "Hummingbirds" but not as "Corals" as this is a category that is not a direct child of "Birds".
I came across this stack overflow question, but it avoids rendering posts that do not match the criteria all together. I still want to fetch and render posts that are in other categories, but only list the categories if they match.
If it's totally fine to hardcode category then you can simply compare categories parent's slug or id to hardcoded value.
Here I am using the slug to compare parent, you can also use id it's totally up to you.
{% for category in post.categories %}
{% set parentCat = category.getParent().first() %}
{% if parentCat.slug == 'birds' %}
<!-- here we are ^ comparing ^ please replace value as per your need -->
{{ category.name }}
{% if not loop.last %}, {% endif %}
{% endif %}
{% endfor %}
now it should only show a categories which have a parent category having given slug.
if any doubt please comment

Concatenate in an element acf fields or an objects

I'm trying to concatenate a Twig variable and an ACF options field but it doesn't work.
I have two footers and I want to select the correct one according to the correct page.
{% if post.slug == "page1" %}
{% set pageType = "pages" %}
{% elseif post.slug == "page2" %}
{% set pageType = "otherspages" %}
{% endif %}
<footer id="footer">
<h2>{{ options.footer_~pageType~_titre }}</h2>
<div>{{ options.footer_~pageType~_container }}<div>
</div>
The ACF fields are called footer_page_titre or footer_otherpage_titre depending on the footer I want to display
Thank you
Try constructing the field name first, for example with the twig format filter which formats a given string by replacing the placeholders, similar to sprintf, and then access the field value by in the options data array.
Construct the field name:
{% set footer_title = "footer_%s_title"|format(pageType) %}
Access the value by array key
<h2>{{ options[footer_title] }}</h2>

Drupal 8, Twig - how to output fields from a custom view template, and check for taxonomy terms

I want to output the values of a taxonomy field that's rendered from a view:
<h4>{{ label }}</h4><!-- Does show -->
<p>{{ content.field_event_type }}</p><!-- Doesn't show -->
<p>
{{ content.field_date }}<!-- Doesn't show -->
<br>{{ content.field_location }}<!-- Doesn't show -->
</p>
Read event details
Also, field_event_type is a taxonomy field. I'd like to be able to check if it has a given taxonomy, as well as output the values as above. For example:
{% if content.field_event_type.has_term("webinar") %}
<p>Is webinar</p>
{% endif %}
But I can't find anything to do this.
Try this
{% set tid = node.yourTaxonomyField.target_id %}
{% if tid %}
{{ drupal_field('field_desired_field', 'taxonomy_term', tid) }}
{% endif %}

HuBL: How to check what lists a contact is part of by contact ID?

I'm trying to show specific content if a user is part of a list in HubSpot.
Psuedo:
If contact_id is part_of_this_list then do this
The contact ID at the moment is being obtained from the query string. I'm trying to check if the user is part of said list, but it's not working.
Approach:
{% set id_querystring = request.query_dict.id %}
{% set registration_list_id = "6136" %} <!-- id of the list I'm checking -->
{% if id_querystring in registration_list_id %}
contact is part of list
{% else %}
contact is not part of list
{% endif %}
i use this code:
{% set list_variable = request_contact.list_memberships|pprint %}
{% if "id of the list you are checking" in list_variable %} ← without the quotes
yes, you are in the list
{%else%}
No, you are not in the list
{%endif%}

Set a property value in an existing twig object

I would like to define a twig object that contains two properties :
The first one is a short text
The second one is a large text (so, i need to use {% set %}{% endset %} to keep readability of the template)
I first tried like this :
{% block principal %}
{% set a_form_help = {'help_toggle_label': 'See the big form field tip', 'help_content': ''} %}
{% set a_form_help.help_content %}>
<h1>This is rules for the field</h1>
<p>A looonng text that will be contained in a collapsed block</p>
<p>And several lines of tips for this field</p>
{% endset %}
{% endblock %}
But Twig complains about the use of the dot in the second {% set %} tag (for setting the large text content in the help_content property).
I've found this message (Twig - Why does it not allow us to set object / array values?) and then done this workaround by using a temporary variable:
{% block principal %}
{% set tmp_help_content %}>
<h1>This is rules for the field</h1>
<p>A looonng text that will be contained in a collapsed block</p>
{% endset %}
{% set a_form_help = {'help_toggle_label': 'See the big form field tip', 'help_content': tmp_help_content} %}
{{ dump(a_form_help) }}
{% endblock %}
I've used a a temporary variable since using the merge() filter would give the same result.
Is this workaroud a good practice or is there a better/cleaner way ?
Thanks in advance for any tip|advice ! :-)
There is no clean way to do it in twig.
Is this workaroud a good practice or is there a better/cleaner way ?
It is not a good practice. As twig is a templating language its responsability is only to display data, not to structure it. Your View Object should have been created elsewhere

Resources