Skip to content

Yield and section tags are affected by order #3286

@jasonvarga

Description

@jasonvarga

Bug Description

The order in which yield and section tags are used can affect the result.

For example, if the yield tag is parsed before the corresponding section tag, it won't work.

How to Reproduce

Use a yield tag before a section tag. The example provided to us was a dark mode toggle with accompanying js that needed to go in the head.

// layout

<html>
<head>
  {{ yield:dark_mode }}
</head>
<body>
  <nav>
    ...
    {{ partial:dark_mode_toggle }}
  </nav>
  {{ template_content }}
</body>
// dark_mode_toggle

<button>toggle</button>
{{ section:dark_mode }}
<script>some js</script>
{{ /section:dark_mode }}

If the section tag was used inside the template it would work, because the template (and therefore the section tag) would be parsed before the layout.

Extra Detail

A solution might be to change how the yield tag works.
Maybe it could output a placeholder string rather than performing the replacement right there.
Then, after the whole view (template+layout) has been rendered, it could replace all the yields.

Environment

Statamic version: 3.0.44

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions