Skip to content

Conversation

@hyperNURb
Copy link
Contributor

Took a stab at implementing the push/stack feature discussed in #183 to enable components to inject content (scripts, styles, metadata).

What's New

  • <c-stack name="..."> - Declares a stack location where content will be rendered
  • <c-push to="..."> - Pushes content to a named stack from anywhere in the template
  • Automatic deduplication - Prevents duplicate content when components are used multiple times
  • Optional middleware - CottonStackMiddleware for post-render processing
  • Flexible control - multiple flag, custom key/id for deduplication

Example

<!-- base.html -->
<html>
  <head>
    <c-stack name="head" />
  </head>
  <body>...</body>
</html>

<!-- tooltip.html -->
<div class="tooltip">{{ slot }}</div>

<c-push to="head">
  <script src="{% static 'js/tooltip.js' %}"></script>
</c-push>

Feedback appreciated! 🙏

@hyperNURb hyperNURb changed the title Push Stacks Add support for Push Stacks Oct 1, 2025
@wrabit
Copy link
Owner

wrabit commented Oct 7, 2025

Hi - thanks for the PR.. I also have a branch for this which is quite complete and for sure will have some overlap with yours, I also reflect on the sub thread here regarding using a single portal tag with attrs (name|to) and unique attribute. I will plan some time soon to review it and take it forward and will be checking your branch for anything I missed.. 👍

@hyperNURb
Copy link
Contributor Author

@wrabit Want me to update this PR per the sub-thread, or would you rather move ahead with your branch? Either works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants