While making my new teme with twig I realize tat is ignoring all te proprieties I added in block--system-branding-block.html.twig to the logo img and rendering it from stable/templates/image.html.twig
My custom code is very simple, just adding a class to the img to modify it using css:
{% block content %}
{% if site_logo %}
<a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home" >
<img src="{{ site_logo }}" alt="{{ 'Home'|t }}" class="site-logo"/>
</a>
{% else %}
<div class="site-name">
<h1 id="site-name">
<a href="{{ path('<front>') }}" title="{{ 'Home'|t }}" rel="home">{{ site_name }}</a>
</h1>
</div>
{% endif %}
{% if site_slogan %}
<div class="site-slogan">{{ site_slogan }}</div>
{% endif %}
{% endblock %}
So I should get for logo:
<a href="<front>" title="Home" rel="home" >
<img src="mylogo.svg" alt="Home" class="site-logo"/>
</a>
And getting instead:
<img src="logo.svg" alt="Inicio" typeof="foaf:Image">
As yo see, no link, no custom class, on theme debug show:
BEGIN OUTPUT from 'core/themes/stable/templates/field/image.html.twig'
just over the logo img and its ends just after, should not read the image.htl.twig and use the block--system-branding-block.html.twig file only for the branding section
Also is ignoring the if and rendering the site-name without any style
Comment | File | Size | Author |
---|---|---|---|
#8 | block--system-branding-block.html_.twig_.txt | 959 bytes | huma2000 |
#8 | page.html_.twig_.txt | 8.38 KB | huma2000 |
Comments
Comment #2
huma2000 CreditAttribution: huma2000 commentedComment #3
huma2000 CreditAttribution: huma2000 commentedComment #4
joelpittetTagging.
Is it picking up your branding block file at all? Could you post the path that twig debug outputs?
Comment #5
huma2000 CreditAttribution: huma2000 commentedHere is the printout of twig debug:
There you can see that is starting to print my template, then changes to img.html.twig from stable and then says that finish with my template, but ignoring all the markup on it and just printing plain text instead the formatted one.
Comment #6
joelpittetI've got a guess. Can you post your page template. Specifically the part of the page the block he's placed into ?
Comment #7
joelpittetComment #8
huma2000 CreditAttribution: huma2000 commentedHere you are (just remove the .txt from them).
I cannot always reproduce it, seems to happen randomly now, dunno why.
Comment #9
star-szr(Until proven otherwise)
Comment #10
Jeff Burnz CreditAttribution: Jeff Burnz commentedWell, basically it looks like the branding vars are being printed in the page template, so is the block even enabled at all? Did you place the branding block in a region?
Comment #11
huma2000 CreditAttribution: huma2000 commentedblock is placed in header region, is being rendered, just sometimes from the wrong template.
Sees not to happen now I reinstalled d8 from scratch and copy te theme over... maybe was something wrong on my installation? Was an updated install since the first rc
Comment #12
Jeff Burnz CreditAttribution: Jeff Burnz commentedComment #14
Spanners CreditAttribution: Spanners as a volunteer commentedI know this has been closed as fixed, but in case this helps someone else.
If you have copied the block--system-branding-block.html.twig from core/theme/Bartick/templates into your custom theme, ensure that the Site Branding block is placed in a region of your page/s.
Turn off the Site Logo and Site Name in the Appearance settings for your custom theme.
Then configure the Site Branding block to display the Site Logo, Site Name or both.
Your changes to the block--system-branding-block.html.twig should be reflected in the Site Branding block.
Comment #15
silverham CreditAttribution: silverham at EY Digital commentedI would also like to add to this as another way the system branding block twig file might not be displayed.
If you have a block e.g.
myblockid
(at/admin/structure/block/manage/myblockid
) and it is a system branding block then the block suggestions are as follows (as usual and if you no template override files / no preprocess functions):It uses the block--system-branding-block.html.twig from Drupal core system module.
(core\modules\system\templates\block--system-branding-block.html.twig)
HOWEVER:
If you have preprocess function that targets the block ID
myblockid
:Then the suggestion of
block--myblockid.html.twig
will be detected as the one to use. However, if no suchblock--myblockid.html.twig
file exists, Drupal will "backtrack" to "block.html.twig" by removing the double dashes.So you will have (incorrectly or as a feature?):
@see
Drupal\Core\Theme\Registry::completeSuggestion()
Instead, you should use
mytheme_preprocess_block__system_branding_block()
, but if you have the system branding block displayed twice and don't want the preprocess function effecting both, then duplicate theblock--system-branding-block.html.twig
file intoblock--myblockid.html.twig
and adjust as usual.In Summary, if you are using a preprocess function targeting the block Id
mytheme_preprocess_block__myblockid()
, then change it tomytheme_preprocess_block__system_branding_block()
, otherwise create duplicate the block intoblock--myblockid.html.twig
.