Score:0

How to render a Taxonomy Term in twig without the term name?

au flag

For some reason, I am writing my own controller that needs to include a taxonomy term.

I want to render everything of a taxonomy term (except the name / title) in the template I wrote.

My controller is like this:

use Drupal\Core\Controller\ControllerBase;

class MyController extends ControllerBase {

  /**
   * Drupal\Core\Entity\EntityTypeManagerInterface definition.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Showing something special about a taxonomy term.
   */
  public function viewTerm(TermInterface $term) {
    $viewBuilder = $this->entityTypeManager->getViewBuilder('taxonomy_term');
    $content = $viewBuilder->view($term);

    return [
      '#theme' => 'my_theme',
      '#content' => $content,
    ];
  }

}

The twig template I'm using:

<div>
  {{ content | without('name') }}
</div>

For some reason, neither without('name') nor without('title') work for my case. Is there a way to do this?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.