1

I have a site with Drupal 8 and I want to customize the templates of my pages.

I use the module:

Here is my template to customize the profile page:

{#
/**
 * @file
 *
 * Default theme implementation for profiles.
 *
 * Available variables:
 * - content: Items for the content of the profile.
 *   Use 'content' to print them all, or print a subset such as
 *   'content.title'. Use the following code to exclude the
 *   printing of a given child element:
 *   @code
 *   {{ content|without('title') }}
 *   @endcode
 * - attributes: HTML attributes for the wrapper.
 * - profile: The profile object.
 * - url: The profile URL, if available.
 *
 * @ingroup themeable
 */
#}
<div{{ attributes.addClass('profile--personnel--teaser') }}>

  <div class="views-row">

    <h3 class="views-teaser-title">
      {{ ??? USERNAME ??? }}
    </h3>

  </div>

</div>

How to display the user name that created the profile (the owner of the profile) ?

1

You can get from getOwner() method

  {{ profile.getOwner().name.value }}
  {{ profile.getOwner().mail.value }}
  • Thanks, this does not work and displays the following error Twig_Error_Syntax: Unexpected ")". in Twig_Lexer->lexExpression() (line 35 of /home/www.domaine.com/public_html/web/themes/contrib/bootstrap_subtheme_front_office/templates/profile--personnel--teaser.html.twig). – user84727 Apr 13 '18 at 6:42
  • See the updated code. There was an extra ) in the code. – Razeem Ahmad Apr 13 '18 at 11:30
  • Thank you, it works ;-) I do not know this function. Does this work with all entities? How to display the rendered entity of a user's display? How to display the user's photo using an image style? – user84727 Apr 13 '18 at 12:26
  • Install the devel module and use kint() to debug the variables – Razeem Ahmad Apr 13 '18 at 12:27
  • Try this {{ profile.getOwner().user_picture.entity.url() }}. It should get image URL – Razeem Ahmad Apr 13 '18 at 12:35

Your Answer

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