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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

huma2000 created an issue. See original summary.

huma2000’s picture

Issue summary: View changes
huma2000’s picture

Issue summary: View changes
joelpittet’s picture

Issue tags: +Twig

Tagging.

Is it picking up your branding block file at all? Could you post the path that twig debug outputs?

huma2000’s picture

Here is the printout of twig debug:

  <div>
    

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'block' -->
<!-- FILE NAME SUGGESTIONS:
   * block--alteamorgan-branding.html.twig
   x block--system-branding-block.html.twig
   * block--system.html.twig
   * block.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/alteamorgan/templates/block--system-branding-block.html.twig' -->


<section id="block-alteamorgan-branding" class="contextual-region block-alteamorgan-branding block block-system block-system-branding-block">
  
  
    <div data-contextual-id="block:block=alteamorgan_branding:langcode=es"></div>

    <div >
    
    

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'image' -->
<!-- BEGIN OUTPUT from 'core/themes/stable/templates/field/image.html.twig' -->
<img src="http://192.168.224.250/adri/themes/alteamorgan/logo.svg" alt="Inicio" typeof="foaf:Image" />

<!-- END OUTPUT from 'core/themes/stable/templates/field/image.html.twig' -->

Altea MoganLa escritora favorita de Nyarlathotep

      </div>
  
  </section>

<!-- END OUTPUT from 'themes/alteamorgan/templates/block--system-branding-block.html.twig' -->

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.

joelpittet’s picture

I've got a guess. Can you post your page template. Specifically the part of the page the block he's placed into ?

joelpittet’s picture

Version: 8.0.0 » 8.0.x-dev
huma2000’s picture

Here you are (just remove the .txt from them).
I cannot always reproduce it, seems to happen randomly now, dunno why.

star-szr’s picture

Category: Bug report » Support request

(Until proven otherwise)

Jeff Burnz’s picture

Well, 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?

huma2000’s picture

block 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

Jeff Burnz’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Spanners’s picture

I 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.

silverham’s picture

I 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):

<!-- THEME HOOK: 'block' -->
<!-- FILE NAME SUGGESTIONS:
   * block--myblockid.html.twig
   x block--system-branding-block.html.twig
   * block--system.html.twig
   * block.html.twig
-->

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 :

function mytheme_preprocess_block__myblockid(&$variables) {
 // Code.
}

Then the suggestion of block--myblockid.html.twig will be detected as the one to use. However, if no such block--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?):

<!-- THEME HOOK: 'block' -->
<!-- FILE NAME SUGGESTIONS:
   * block--myblockid.html.twig
   * block--system-branding-block.html.twig
   * block--system.html.twig
   x block.html.twig
-->

@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 the block--system-branding-block.html.twig file into block--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 to mytheme_preprocess_block__system_branding_block(), otherwise create duplicate the block into block--myblockid.html.twig.