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

Enable inlined expressions in layout populated by page handlers #135

Open
dvogel opened this issue Nov 22, 2024 · 0 comments
Open

Enable inlined expressions in layout populated by page handlers #135

dvogel opened this issue Nov 22, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@dvogel
Copy link
Collaborator

dvogel commented Nov 22, 2024

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>
@dvogel dvogel added the enhancement New feature or request label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant