Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By anoopmohan on
Hi,
I have created a custom user template (user.html.twig) and added some CSS class for only that template to change the display format/layout only when the user check the profile details. I have added this template in Drupal/core/themes/bartik/templates. It seems to be working fine in the case when loading user profile page, but the other templates (contents / articles etc) got affected by this code change.
I would like to know, if there is any mechanism to change the layout only for the user.html.twig? Please note that I am working on Drupal 8.x version.
Thanks,
Comments
First thing - don't hack core
First thing - don't hack core! You should not be doing anything in /core/, if you want to modify Bartik create a sub-theme, or copy it and rename stuff (lots of docs on creating sub-themes). Next time you update Drupal you will overwrite Bartik and your changes are gone - otherwise you are forever maintaining a hacked version of Drupal - not fun in the long run.
OK, you're actual issue. Do you have user pictures? Do you think it's the user picture stuff that is messing up the articles?
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
New layout for user profile page
Hi Jeff,
Thanks for the reply.
The current "user.html.twig" template in core/modules/user/templates/user.html.twig just displays all the content without any specific layout.
Code:
{% if content %}
{{- content -}}
{% endif %}
So, I have created a new custom template with same name "user.html.twig" and placed it in the location "/core/themes/bartik/templates/" and modified the code in it to add new layout for the page. Yes, I have a user picture which needs to be displayed along with user profile details.
Here I would like to know
1) If there is any alternate way to add a new layout for the user profile page (if editing the /core/ is not a proper way) ?
2) If there is any mechanism to change the layout only for a single template without affecting other templates?
Thanks,
1) If there is any alternate
I already answered this - create a sub-theme of bartik in /themes/
Yes, template suggestions and overrides. I don't want to go further before one more question: can you paste in the output of the user template (the source code from your browser when viewing a user profile) and the output of an article (again, from the browser source) that is messed up, please use the code tags so it's properly formatted.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Page Source
Hi Jeff,
Please find the page source from browser below.
User profile page:
Content page:
Thanks,
He meant your *.twig template
He meant your *.twig template, not the source of your webpage. :-D
Also, i repeat.. create a sub theme, don't modify a core theme (ie, Bartik). https://www.drupal.org/theme-guide/8/creating-a-sub-theme
-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien
Adding sub theme
:-D
Thanks for the support.
Let me check it after adding a sub-theme.
Thanks,
No actually, I want to see
This is good, I wanted to see the source from the browser - because there can be lots of stuff hiding in a variable, I want to see whats actually going on after the page has rendered - so perfect, this is great.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thanks
Thanks Jeff for your support.
Yeah, I haven't given an
Yeah, I haven't given an answer because the answer is rather complicated, and I was going to write a blog post on it as others will get bitten by the exact same issue.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Great !. Please share the link
Great !. Please share the link, once you finish your blog. Thanks Jeff.