1

I've been to figure out how I can output the machine-name of a taxonomy term on my entity field to my twig template. using .label prints out the name of the taxonomy term. .id get a numerical value, was actually hoping to get the machine term instead. Using kint I can't seem to find it

{% for themes in node.field_themes %}

        <span>{{ themes.entity.id }}</span>
{% endfor %}
  • 1
    You can try this one {{ themes.entity.name|lower|replace({' ': '-'}) }} – Alex Kuzava Jul 26 '18 at 10:02
  • using .entity.id output a numerical value – clestcruz Jul 26 '18 at 10:04
  • 1
    @AlexKuzava the correct way is {{ themes.entity.label|lower|replace({' ':'-'}) }} but thanks for the hint. Kindly submit this as an answer – clestcruz Jul 28 '18 at 5:05
2

I see, the output I'm looking for somewhat like the key value of a list field. For example Taxonomy term it becomes taxonomy-term

As discussed the correct way is

{{ themes.entity.label|lower|replace({' ':'-'}) }}

It's suitable for other entity types as well

| improve this answer | |
1

Taxonomy terms are content entities, and don’t have machine names.

They have IDs, that’s how they’re generally identified.

| improve this answer | |
  • I see, the output I'm looking for somewhat like the key value of a list field. For example Taxonomy term it becomes taxonomy-term – clestcruz Jul 26 '18 at 9:38
  • You probably need to use php to achieve that. Preprocess the theme and use preg_replace or something. – Beebee Jul 26 '18 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.