craftcms / craftcms/cms

[3.x]: {{ endBody() }} Tag is not replacing templates end of body for {% js %}

Open
#11,533 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug craft3
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

When the {{ endBody() }} tag is added within an include block, any {% js %} tag I use gets fired twice. Once at the {% endBody() %} and once right before the </body>. I've solved the problem by just removing the {% endBody() %} tag, but it's not expected behavior.

Steps to reproduce
  1. Create basic html block template, use at least one {% include %} statement.
  2. Place {% endBody() %} tag within the {% include %} template file
  3. Use {% js %} within any template, view rendered page source to see the duplicate
Expected behavior

Rendered template javascript should appear on the page where {% endBody() %} is used, and not at the end of the document before </body>.

Actual behavior

Rendered template javascript is appearing both where {% endBody() %} is used, as well as at the end of the document before </body>

Craft CMS version

3.7.46

PHP version

8.0

Operating system and version

Linux 5.10.104-linuxkit

Database type and version

MySQL 5.7.38

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-35)

Installed plugins and versions

Embedded Assets 2.11.3
Feed Me 4.5.3
Imager v2.4.0
Redactor 2.10.9
SEO 3.7.4
Super Table 2.7.2
Typed link field 1.0.25

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue on Craft CMS 3.7.46 using an HTML block template with an include, placing {% endBody() %} in the included template and {% js %} in a template. Inspect the rendered page source to trace the include, endBody() and js entry points. Done means the JavaScript appears once at the endBody() location and not again before </body>.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.