nystudio107 / craft-templatecomments

Adds a HTML comment with performance timings to demarcate `{% block %}`s and each Twig template that is included or extended.
https://nystudio107.com/
MIT License
20 stars 1 forks source link

When overwriting a block from a parent template - comments are getting printed into final result. #25

Closed MichaelBrauner closed 3 years ago

MichaelBrauner commented 3 years ago

Describe the bug

When extending a template base.html.twig :

<!DOCTYPE html>

<html lang="{{ craft.app.language }}">

<head>
    <title>{% block title %}{{ siteName }}{% endblock %}</title>
</head>

And try to change the title:

{% extends 'base.html.twig' %}

{% if entry %}
     {% block title %} {{ entry.title }} {% endblock %}
{% endif %}

Comments are printed into final result:

<title>
&lt;!-- &gt;&gt;&gt; BLOCK BEGIN &gt;&gt;&gt; title --&gt;
 Kontakt 
&lt;!-- 0.01ms &lt;&lt;&lt; BLOCK END &lt;&lt;&lt; title --&gt;
</title>

Expected behaviour

No comments should be printed into final result.

Versions

khalwat commented 3 years ago

There is a block present, though, I'd expect that there would be comments output to indicate that block?

Can you help me understand why you believe this is a bug?

MichaelBrauner commented 3 years ago

Ah, I understand now. I have to write the title tag inside the block - otherwise the comments are landing inside of the page title.

Sorry for that. I love your work and your blogposts.

Cheers!

KatieMFritz commented 2 years ago

Hi Andrew! I'm running into this, and I agree that it's expected behavior, but I don't want it. I tried adding title to use the excludeBlocksThatContain setting, but no luck. Is that because the block itself is called title, but it doesn't contain the word title?

khalwat commented 2 years ago

Use the excludeBlocksThatContain config setting @KatieMFritz :

https://github.com/nystudio107/craft-templatecomments/blob/develop/src/config.php#L44

If should work if the block is or contains title -- what version of the plugins are you using? Note: You might have to clear template caches after changing this setting, for it to apply to your compiled templates.