0

I have a site built with Drupal 8 and the Twig Tweak module. I want to make the current user's frontpage_tasks display mode on my home page. How to do this ?

I can make a user's frontpage_tasks display mode by manually entering their ID :

page--front.html.twig :

{{ drupal_entity('user', 51, 'frontpage_tasks') }}
{{ drupal_entity('commerce_store', ???, 'frontpage_tasks') }}
{{ drupal_entity('group', ???, 'frontpage_tasks') }}

For stores, I want to display all stores that the current user owns.

For groups, I want to display all groups whose current user is the creator.

What I want to do is render the current user account, stores and groups with frontpage_tasks view mode.

3
  • Comments are not for extended discussion; this conversation has been moved to chat. – Clive Oct 5 '20 at 7:45
  • 1
    The problem is that a page normally shouldn't have a cache dependency for the current user. If you placed this as a block via the block layout this dependency would be resolved automatically. This block could be built by a custom block plugin or Views. – 4k4 Oct 5 '20 at 7:56
  • @4k4 I don't want to save my view, I want to delete it. I'm trying to put a simple TWIG code. I don't have a cache problem. No problem making the display mode current user. I still have to do the stores and groups of the current user. – mathieu Oct 5 '20 at 12:58
1

In a Twig template you can get the current user id with user.id.

With the help of Twig Tweak you can use it to render the user entity:

{{ drupal_entity('user', user.id, 'full') }}

As discussed in the comments this only works if your template has already a cache context for the current user.

2
  • I already have the answer from Sssweat and it works. My problem is with stores and groups. See chat – mathieu Oct 5 '20 at 14:10
  • 1
    I took a different approach in answering the original question with the main focus on caching. For other topics like stores or groups please ask separate questions providing more details. – 4k4 Oct 5 '20 at 14:50

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.