bernhard Posted August 22 Share Posted August 22 Almost any website that I build needs some kind of differently coloured sections... Unfortunately this is not so easy to accomplish. I've come up with several concepts over the time, but this one is very cool and promising imho ? Anybody interested in more details or is that something nobody needs? How did/do you solve that? Link to comment Share on other sites More sharing options...
FireWire Posted August 26 Share Posted August 26 On 8/22/2024 at 2:35 AM, bernhard said: How did/do you solve that? I only build websites in black and white. Color is a paid extra. 3 Link to comment Share on other sites More sharing options...
herr rilke Posted September 5 Share Posted September 5 On 8/22/2024 at 11:35 AM, bernhard said: Anybody interested in more details or is that something nobody needs? How did/do you solve that? yeeees! me, me, me, me, MEEEEE 🙂 please do let us know! as an contao-webmaster i solve this by using custom classes an editor is able to choose from per section - looks a little like your approach 1 Link to comment Share on other sites More sharing options...
herr rilke Posted November 20 Share Posted November 20 say @bernhard is there a chance that you'd introduce us to the art of mulit-colored section backgrounds?? 😇 Link to comment Share on other sites More sharing options...
bernhard Posted November 21 Author Share Posted November 21 Hey @herr rilke thx for your interest. Unfortunately nobody else showed interest so it looks like a video would not be interesting to a lot. On 9/5/2024 at 5:43 PM, herr rilke said: as an contao-webmaster i solve this by using custom classes an editor is able to choose from per section - looks a little like your approach I did that as well, but what I don't like with that approach is that if you move a block you have to adjust all classes of all blocks which is tedious. My approach works similar but different 😛 I use a dedicated block type solely for the color. This block sets a custom runtime flag (like $site->bgColor) and all blocks then add a custom class based on that bgColor flag's value. So once I have a color block with setting "muted" all following blocks might get the class "bg-muted", for example. Then when the next color block comes up it might set the bgColor flag to "primary" which would tell all following blocks to add the class "bg-primary". Now the challenge is to make that work with spacings and with frontend editing. On frontend editing the problem to solve is with sorting blocks, because classes come from php and sorting is done on the client with JS. So you need to add a little js to adjust classes once sorting happens. In my project this is done like this: // section color updates on sort document.addEventListener("rocksortable-added", (event) => { let sortable = event.detail; sortable.option("onMove", (e) => { setTimeout(() => { let el = e.dragged; let container = el.closest("[sortable]"); let children = container.children; let colorClass = null; // loop all items and update color classes for (let i = 0; i < children.length; i++) { let child = children[i]; // don't change class of dragged item if (child.classList.contains("sortable-drag")) continue; // update colorClass on every rpb-color block if (child.classList.contains("rpb-color")) { colorClass = child.getAttribute("data-col"); continue; } // update colorclass of element if (!colorClass) colorClass = "white"; child.classList.remove("has-bg-white"); child.classList.remove("has-bg-muted"); child.classList.remove("has-bg-primary"); child.classList.remove("has-bg-secondary"); child.classList.add(`has-bg-${colorClass}`); } }, 0); }); }); For block spacings I've switched my approach from PHP based calculations to CSS based calculations. The trick is to only use margin-top for blocks, because then you can define different margins for blocks based on the previous block like this: .bg-white + .bg-muted { margin-top: 20px; } This way you can achieve a lot of flexibility in your design with very little complexity in code. Hope that helps! 1 Link to comment Share on other sites More sharing options...
herr rilke Posted November 22 Share Posted November 22 hello @bernhard, wonderful! Thank you very much for the time you took to explain this!! I will definitely recreate this! It reminds me of the concept of "envelopes", where there is a beginning and an end element. This makes it possible, for example, to say, "from here on everything in 3 columns" or something like that. But that would probably require not only an initial element, but also an end element... hmm, I'll have to think about it. Link to comment Share on other sites More sharing options...
bernhard Posted November 22 Author Share Posted November 22 Glad it was helpful @herr rilke! Yeah that would be possible. Another option would be to solve it with nested elements, so you'd have a "color" container that can hold other blocks (like headline, text, image, etc). Even that would already be possible using RockPageBuilder and @Stefanowitsch did something quite crazy in this regard and hopefully shares it one day with us 😉 But I try to not introduce any kind of multi-level editing for clients. I try to keep things as simple as possible and only add necessary features. But coloured sections is one of them imho. 1 Link to comment Share on other sites More sharing options...
herr rilke Posted November 23 Share Posted November 23 yes, I saw @Stefanowitsch's post - very impressive! and it's also good to know that envelopes / nested elements are already possible. I'll go play a little 🙂 have a nice weekend ! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now