theming – How to make the author info on the custom fields on the comment model and twig node in drupal8?

I'm trying to give the author the full name and information about the other customs fields of the authors in comment.html.twig and node.html.twig. But none of the fields I've created for users, such as "First Name", "Last Name", and Auther UID, etc., are displayed in comments.

I've tried with the following code for the comment writer

{{}} Comments.author.field-first_name.entity.value
{{}} Comment.author.user_picture.0.entity.uri.value
{{}} Comments.author.uid.entity.value

And, I've tried the following code for the author of the node:

{{}} Node.author.field-first_name.entity.value
{{}} Node.author.user_picture.0.entity.uri.value
{{}} Node.author.uid.entity.value

Ideas, how can I make this information in the comment template?

theming – 8 – how to trigger a modal from a twig pointing to a controller returning an AJAX response

I'm trying to trigger a modal from a twig. The modal path is a controller that returns an AJAX response as below:

Routing code

usgbc_myaccount.get_badges_evidence_controller:
path: & # 39; / account / get-badges-evidence / {badge_type} & # 39;
by default:
_controller:
& # 39;  Drupal  usgbc_myaccount  Controller  GetBadgesEvidenceController :: getEvidence & # 39;
_Title: & # 39;
requirements:
_permission: & # 39; access content & # 39;
_format: & # 39; html & # 39;

Controller code

Drupal namespace  usgbc_myaccount  Controller;



the GetBadgesEvidenceController class extends ControllerBase
{
/ **
* @return AjaxResponse
* /
public service getEvidence ($ badge_type)
{

$ options = [
      'width' => '50%',
    ];

$ response = new AjaxResponse ();
$ response-> addCommand (new OpenModalDialogCommand (t (modal title)),
$ badge_type, $ options));

return $ response;
}
}

Call a router from a twig template

{{& # 39; Read more & # 39; | t}}

When I click on the link, the answer appears in JSON in the text box of another page. What is missing? Is the approach correct? Any help would be appreciated.

Thank you

Print view header with the help of Twig Tweak

I would like to print the header for a view, but not the rest of the content using twig tweak. I've tried variations on

{{drupal_view (& # 39; VIEW_NAME & # 39; PAGE_NAME & # 39 ;, & # 39; view_header & # 39;)}}

But that does not work, it displays the entire view.

theming – duplicate content in twig

i want to show 3 products online and after show the picture the problem when i create the twig

{% for the line in the% lines} {% for i in 1..3%} {{}} Row.content {% endfor%} <img src = "http://drupal.stackexchange.com/ {{photo}}" alt = "banner" class = "center-img"

height = "10%" width = "80%">
{% endfor%}

the problem I see the same product online but I want to show products 1 and 2 and 3

8 – Drupal8 field of view in Twig

I need to convert the following D7 to D8 in my twig file of view. I have tried the following but it does not work.

Code D7:

result[$id]-> field_field_document_upload[0]["rendered"]["#file"]-> file size; ?>

Code D8 in Twig:

            {{see resulthttps://drupal.stackexchange.com/q/276964.field_field_document_upload[0]["rendered"]["#file"].file size }}

What's the problem

8 – How to use a twig if statement in a view rewrite

How can I add a rewrite of the Views with Twig field that will display the moderation status only if the node is in Draft or Revision state. I've tried this below, but his prints are also 'Published & # 39; and I only want to post it as a draft.

{{title_1}} {% if field.moderation_state == draft%}
{{}} Moderation_state
{% end if %}
{% end if %}

I've also tried variants like this one

{% if moderation_state__value == & # 39; draft & # 39;%}

You will find below the replacement models available.

            {{moderation_state}} == State of Moderation
{{path}} == Link to content
{{title_1}} == Title
{{title_1__value}} == Gross value
{{arguments.nid}} == Content: title of the ID
{{raw_arguments.nid}} == Content: ID entry

8 – How to query the title of the field of view in twig?

I replace the views-view-field.html.twig model file. Inside the template, I have to get the correct translation of the field_title. Currently, the file looks like this

{{output -}}

I was trying few options to find the right translation.

{{}} Fields.title.content.langcode

But it does not work. langcode has moved from the pretreatment function from the .theme.
Can you help me?

8 – How to add a comment field to my custom Twig template

Use this code in the YOUR_Module.theme file of your theme:

function YOUR_MODULE_preprocess_node (& $ variables) {
// if you will probably want to use it for certain types of content.
if ($ variables['node']-> getType () == & # 39; YOUR_CONTENT_TYPE & # 39;) {
$ variables['comment_count'] = $ variables['node']-> get (& # 39; YOUR_COMMENT_FIELD & # 39;) -> comment_count;
}
}

And then you can use it in your comment.html.twig file as if:

{{comment counter}}

8 – otherwise the condition does not work in my code in the twig pattern

In the code given below

content.field_image_link[0]['#url']

is empty but it still enters the if condition and adds html

which is incorrect in the code below because of which he enters the if
condition then that it should go into the second if condition given below

{% if content.field_image_link[0][‘#url’] %}

{% block paragraph%}    

 

    {% block content%}

{% if content.field_image_link[0]['#url']    %}



{{}} Content.field_image_2
       

{{Content.field_image_link[0]['#title'] }}

{% end if %} {% if content.field_image_link[0]['#url'] == & # 39;% # {{}} Content.field_image_2

{{Content.field_image_link[0]['#title'] }}

{% end if %} {% endblock%}
{% endblock paragraph%}