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

[Turbo] Include minimal layout for Turbo Frames #2318

Open
wants to merge 10 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Turbo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2.22.0

- Include minimal layout for Turbo Frames
- Add `<twig:Turbo:Stream>` component
- Add `<twig:Turbo:Frame>` component

Expand Down
36 changes: 36 additions & 0 deletions src/Turbo/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,42 @@ With content:
A placeholder.
</turbo-frame>

Minimal layout for Turbo Frames
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. versionadded:: 2.22

The minimal layout for Turbo Frames was added in Turbo 2.22.

Since Turbo does not need the content outside of the frame, reducing the amount that is rendered can be a useful optimisation. However, this optimisation prevents responses from specifying ``head`` content as well. There are cases where it would be useful for Turbo to have access to items specified in ``head``. To specify the heads, you must then use a minimal layout for frame, rather than no layout. With this, applications can render content into the ``head`` if they want.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reducing the amount that is rendered can be a useful optimisation

I'd present first an example of this (with controller code and renderblock for instance)

However, this optimisation prevents responses from specifying

This part can be removed i think, as the same idea is on the next sentence. And i feel it's a bit fearfull and would not want to alarm users if they dot need any meta tags (which is, as i see it, the most standard case, no ?)

With this, applications can render content into the head if they want.

Maybe something like "it allows you to set meta tags while still having a minimal ...." ?


.. code-block:: html+twig

{% extends '@Turbo/frame.html.twig' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  {% extends '@Turbo/frame.html.twig' %}

    {% block head %}
        <meta name="alternative" content="present" />
    {% endblock %}

    {% block body %}
        <turbo-frame id="frame_id">
            Content of the Turbo Frame
        </turbo-frame>
    {% endblock %}
<!DOCTYPE html>
<html>
  <head>
      <meta name="alternative" content="present" />
  </head>
  <body>
      <turbo-frame id="frame_id">
          Content of the Turbo Frame
      </turbo-frame>
  </body>
</html>

Not sure about this gain :)


{% block head %}
<meta name="alternative" content="present" />
{% endblock %}

{% block body %}
<turbo-frame id="frame_id">
Content of the Turbo Frame
</turbo-frame>
{% endblock %}

{# renders as: #}
<!DOCTYPE html>
<html>
<head>
<meta name="alternative" content="present" />
</head>
<body>
<turbo-frame id="frame_id">
Content of the Turbo Frame
</turbo-frame>
</body>
</html>

Writing Tests
^^^^^^^^^^^^^

Expand Down
10 changes: 10 additions & 0 deletions src/Turbo/templates/frame.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
{% block head %}
{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>