Replacing content of multiple containers #885
Replies: 5 comments 6 replies
-
You can have as many containers as needed: the containers option accepts multiple selectors and isn't limited to a single one. Replacing a main content area as well as a navigation would look like this: const swup = new Swup({ containers: ['main', 'nav'] }) This would require that both containers are always available on all pages. To replace some containers only in certain conditions, you can modify the containers for each visit in a hook: swup.hooks.on('visit:start', (visit) => {
if (visit.to.url === '/about') {
visit.containers.push('#sidebar')
}
}) I'll close this as already implemented, but let me know if I misunderstood your feature request. |
Beta Was this translation helpful? Give feedback.
-
Yes, that explains it. So, it's to define in the script where you want Swup to "swap" content, etc. While doing |
Beta Was this translation helpful? Give feedback.
-
@k16e-me Exactly. The morph plugin comes close to what you're suggesting, it also replaces parts of the pages marked with data attributes. The only "downside" is that it updates elements without animation. Depending on your use case, that might be okay however. It's mostly meant for permanent elements that need to update state or classes, like menus and footers. <nav data-swup-morph="nav">
<!-- Morphed by the morph plugin -->
</nav>
<main id="swup">
<!-- Replaced normally by swup -->
</main> |
Beta Was this translation helpful? Give feedback.
-
O, I'll look more into morph but might not use it for this case (especially needing to avoid any downsides). |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm cycling back to this as I'm observing that if the element to "morph" seems to be just a single/simple tag, swup is skipping it. You can observe the behavior here https://jee-v2.k16e.co/ as you navigate from page to page, the body's main h1 tag with |
Beta Was this translation helpful? Give feedback.
-
Describe the problem 🧐
Currently, only contents within the swup container are swapped/replaced on new page entry. Anything outside is typically left alone. If the head plugin is used, things like title tag and other meta with changing contents get updated. But other than those, there isn't a way to just drop an attribute on a markup which then instructs Swup to watch for it when page changes and swap its content, much like you can drop in a "persist" attribute on an element and Swup knows to leave it alone when swapping pages.
Describe the propsed solution 😎
Provide a way with a simple attribute such as
data-swup-swap
or something along that line for Swup to watch for it when page changes and swap its content.Alternatives considered 🤔
None
How important is this feature to you? 🧭
Would make my life a lot easier
Checked all these? 📚
Beta Was this translation helpful? Give feedback.
All reactions