Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Provide Twig Method to Add to End Body #5955

Closed
davist11 opened this issue Apr 22, 2020 · 3 comments
Closed

[FR] Provide Twig Method to Add to End Body #5955

davist11 opened this issue Apr 22, 2020 · 3 comments
Labels
enhancement improvements to existing features site development 👩‍💻 features related to website/API development
Milestone

Comments

@davist11
Copy link
Contributor

The css and js Twig tags already exist, but it would be really cool if there were a generic tag to add any code/string before the </body> and didn't do any processing to the string being passed in. This is useful for stuff like modals, etc. This is kind of why the Twig Portal plugin was created, except you can choose where the contents gets output too. We solved this by creating a custom Twig function addToEndBody that hooks into EVENT_END_BODY, but it would be pretty cool to see this be a part of core.

public static function add(string $code)
{
    Event::on(
        View::class,
        View::EVENT_END_BODY,
        function(Event $e) use ($code) {
            echo $code;
        }
    );
}
brandonkelly added a commit that referenced this issue Apr 23, 2020
brandonkelly added a commit to craftcms/legacy-docs that referenced this issue Apr 23, 2020
@brandonkelly brandonkelly added enhancement improvements to existing features site development 👩‍💻 features related to website/API development labels Apr 23, 2020
@brandonkelly brandonkelly added this to the 3.5 milestone Apr 23, 2020
@brandonkelly
Copy link
Member

Just added a new html tag, similar to the current css and js tags, but for arbitrary HTML, for Craft 3.5.

{% html %}
    <p>This will be placed right before the <code>&lt;/body&gt;</code> tag.</p>
{% endhtml %}

It will inject the HTML right before </body> by default, but you can change the position by adding at head or at beginBody to the end of the opening tag.

@piotrpog
Copy link

piotrpog commented Jul 8, 2020

@brandonkelly would it be possible to include this change already to 3.4? I feel i would find a good use for it in my current project but 3.5 seems bit far away.

@brandonkelly
Copy link
Member

@piotrpog 3.5 is very close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements to existing features site development 👩‍💻 features related to website/API development
Projects
None yet
Development

No branches or pull requests

3 participants