-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Often a page handler will want to push values up to the layout without defining a full section. For example:
// layouts/default.up
<body class="^pageSlug ^userTheme">
</body>
// pages/other.up
^handler {
pageSlug := "other"
userTheme := LookupUser(...).ThemeSlug() // "elflord"
}
// output
<body class="other elflord">
</body>
However the layout wants to be able to use an expression like this with a clear fallback in the case where the page fails to provide the expression. For example, if the page failed to set either, they could default to empty:
<body class="">
</body>
Obviously simple go expressions won't suffice here. Sections serve a very similar role but they are block based, quite verbose, and require a conditional guard. For example, this will not work:
// layouts/default.up
<body class="^outputSection("pageSlug") ^outputSection("userTheme")">
</body>
It feels like pushup should supply a per-request table that supports primitive values, defaulting to the empty value for each.
// layouts/default.up
<body class="^p.Get("pageSlug") ^p.Get("userTheme")">
</body>
// pages/other.up
^handler {
p.Set("pageSlug", "other")
p.Set("userTheme", LookupUser(...).ThemeSlug())
}
I could even see pushing this toward a special reserved symbol, with pushup translating this block into the ^p.Get(...) syntax above:
// layouts/default.up
<body class="^p.pageSlug ^p.userTheme">
</body>