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

[FR] Add support for {% include %} back into the plugin #40

Closed CreateSean closed 5 months ago

CreateSean commented 2 years ago

Describe the bug

A clear and concise description of what the bug is.

Template comments is not working with matrix blocks in new versions

image

In the screenshot the circled sections are each a matrix block but template comments is not telling me where they are located.


However in a different older site running Craft 3.7.37 and Template Comments 1.1.2 matrix blocks output comments as expected. See below. image

To reproduce

Steps to reproduce the behaviour:

  1. Go to "..."
  2. Click on "..."
  3. See error message "..."

Expected behaviour

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Versions

khalwat commented 2 years ago

Not exactly a bug, but not something you're likely to be happy about... due to compatibility with Twig 3 reasons, I removed the template loader shim that allowed those template delimiters.

You can still pin it to the older version of the plugin for Craft 3 if you want to keep that functionality. Maybe I'll figure out a better way to do it going forward.

Here's a good description from @MangoMarcus https://github.com/nystudio107/craft-templatecomments/issues/43

Question

Is there no support for comments when using {% include %} ?

This plugin works well for {% block %} but the description to me implies it would cover using {% include %}

Adds a HTML comment to demarcate each Twig template that is included or extended.

eg. using {% include '_foo/my-template' %} I'd expect something like

<!-- >>> INCLUDE BEGIN >>> _foo/my-template FROM _foo/other-template -->
<!-- * template output here * -->
<!-- <<< INCLUDE END <<< _foo/my-template FROM _foo/other-template TIME 1.23ms -->

Thanks!

CreateSean commented 2 years ago

Oh... :(

so this is removed in the Craft 4 compatible version, right? What is the most recent version that still has the delimiters? I'll lock to that in my C3 projects.

I'll wait until you figure out the better approach. Love this plugin alot.

khalwat commented 2 years ago

The Craft 4 / Twig 3 version does not log comments for {% include %}s -- but rather only {% block %}s (but those now include the template they are coming from).

The latest version of the Craft 3 plugin is at feature parity with the Craft 4 version, which means you lose the {% include %} comments. If you want to lock in the Craft 3 version that does add {% include %} comments, set your semver to 1.1.2.

No ETA on adding this functionality back into the Craft 4 version of the plugin; it'll have to wait until work settles down a bit on the other plugins.

johnwbaxter commented 2 years ago

I just came here to report this bug! This was what I used this plugin for, for looking at which block from my content builder was doing what and where :)

Really hope it comes back soon! Thanks Andrew!! :)

taya13 commented 2 years ago

Indeed I was also using this plugin for generating comments for includes... I also hope it will come back soon

khalwat commented 5 months ago

Same as https://github.com/nystudio107/craft-templatecomments/issues/43

khalwat commented 5 months ago

So I got this working for Craft 4 (really, for Twig 3.0)... and man it's ugly. But it works.

I'm going to think about it for a bit to see if there are better approaches

khalwat commented 5 months ago

Here's the commit in question: https://github.com/nystudio107/craft-templatecomments/commit/3b6b991cc81fb465d51a8542cfebece1504678db

...with a detailed explanation of the problem here: https://github.com/nystudio107/craft-templatecomments/blob/develop-v4/src/web/twig/TemplateCommentsParser.php#L11

khalwat commented 5 months ago

1.2.1, 4.0.1, & 5.0.0 released with this FR added