Hi,
In my taxonomy term I have a field called paragraph reference which the field type is Entity reference revisions and is referencing to the paragraphs I have created. On this taxonomy term page I just want to access this field and print the paragraphs. When I use devel I see these values but I have tried almost everything but cannot seem to access the field in page--taxonomy--term.html.twig . These are the following things that I have tried but getting no result:
{% for item in content.field_paragraph_reference %}
{{ drupal_entity('paragraph', item.target_id) }}
{% endfor %}
{{ content.field_paragraph_reference }}
{{ content.field_paragraph_reference[0] }}
{% for key, value in content.field_paragraph_reference %}
{% if key > 0 %}
{{ ' , ' }}
{{ content.field_paragraph_reference[key] }}
{% endif %}
{% endfor %}
{{content}}
{% for key, item in content.field_paragraph_reference if key|first != '#'%}
{% for key, item in content.field_paragraph_reference[key]['#paragraph'].field_paragraph_reference %}
{{ drupal_entity('paragraph', item.target_id) }}
{% endfor %}
{% endfor %}
{{ content.field_paragraph_reference['#items'].0 }}
{{ node.field_paragraph_reference.0 }}
{{ ['#term'].tid.value }}
{{node.tid.value}}
{{node.tid.0}}
{{node.tid}}
{{entity.tid.value}}
{{entity.tid.0}}
{{entity.tid}}
{{term.tid.value}}
{{term.tid.0}}
Could you please help out?
stdClass Object
(
[__CLASS__] => Drupal\taxonomy\Entity\Term
[values:protected] => Array
(
[tid] => Array
(
[x-default] => 2011
)
[revision_id] => Array
(
[x-default] => 2919
)
[vid] => Array
(
[x-default] => sector
)
[uuid] => Array
(
[x-default] => cea9bd71-6b2a-4064-8fc3-03ddc9d4c267
)
[langcode] => Array
(
[x-default] => en
)
[revision_default] => Array
(
[x-default] => 1
)
[revision_user] => Array
(
[x-default] => 21
)
[revision_created] => Array
(
[x-default] => 1615382702
)
[revision_log_message] => Array
(
[x-default] =>
)
[isDefaultRevision] => Array
(
[x-default] => 1
)
[name] => Array
(
[x-default] => Autos
)
[description] => Array
(
[x-default] => Array
(
[value] =>
[format] =>
)
)
[changed] => Array
(
[x-default] => 1615382702
)
[default_langcode] => Array
(
[x-default] => 1
)
[status] => Array
(
[x-default] => 1
)
[revision_translation_affected] => Array
(
[x-default] => 1
)
[weight] => Array
(
[x-default] => 0
)
[parent] => Array
(
[x-default] => Array
(
[0] => Array
(
[target_id] => 0
)
)
)
[field_meta_tags] => Array
(
[x-default] => Array
(
[0] => Array
(
[value] => a:2:{s:5:"title";s:42:"Autos";}
)
)
)
[field_paragraph_reference] => Array
(
[x-default] => Array
(
[0] => Array
(
[target_id] => 5241
[target_revision_id] => 23723
)
[1] => Array
(
[target_id] => 5257
[target_revision_id] => 23739
)
[2] => Array
(
[target_id] => 5276
[target_revision_id] => 23758
)
[3] => Array
(
[target_id] => 5995
[target_revision_id] => 26302
)
[4] => Array
(
[target_id] => 5258
[target_revision_id] => 23740
)
[5] => Array
(
[target_id] => 5267
[target_revision_id] => 23749
)
[6] => Array
(
[target_id] => 5280
[target_revision_id] => 23762
)
[7] => Array
(
[target_id] => 5281
[target_revision_id] => 23763
)
[8] => Array
(
[target_id] => 5279
[target_revision_id] => 23761
)
[9] => Array
(
[target_id] => 5286
[target_revision_id] => 23768
)
[10] => Array
(
[target_id] => 6245
[target_revision_id] => 26615
)
[11] => Array
(
[target_id] => 6246
[target_revision_id] => 26616
)
)
)
Thanks.
Comments
If the name of the field is
If the name of the field is 'field_paragraph_reference', then you can print it like this:
But if you want to print certain fields of paragraph, then below is the example of how to do this. Let's say the paragraph has the 'field_text' and we need to print the value of this field. Also, let's say that the 'field_paragraph_reference' is multivalued field. The example:
Hi,
Hi,
I had tried that but it did not work. I guess its because I am using the taxonomy term page view where I want the view to show for certain vocabularies and then for the others I want the paragraph reference to show. However I have fixed it now by using this code -
{% set tid = node.yourTaxonomyField.target_id %}
{{ drupal_field('field_paragraph_reference', 'taxonomy_term', tid) }}
Ok, it seems I didn't
Ok, it seems I didn't understand what template you used. Could you share what is the path (I want to understand how can I get it).
sure, so for example I have a
sure, so for example I have a Sector vocabulary taxonomy term so the path for that is /admin/structure/taxonomy/manage/sector/overview/fields where in here I have a field called paragraph reference. Now in my template file called page--taxonomy--sector.html.twig that is where I have added the above code in. Hope that helps.