I have hit a bit of an issue on a site I am building, we have some block grid, that we can set a color on, Which is normally the outer container, for HTML that works ok.
But the issue I am now having is the fact that we need to set a style on the child blocks that are in the container if a colours set as the back ground.
So Example.
Outer Block would have a back colour and inside the container we have up to 4 columns depending on the block been used.
Each of the cols would then need to check the parent container to see if a back color is set, if it is then we need to apply a style at that point.
The problem is I can’t apply the style on the outer container, as if one or more of the cols dose not have a back color then the text style can’t be applied.
I have a work around in place I set the back color again on each of the cols that needs it. But this is just a work around and I can see it annoying the customer.
I just need a way to get he settings on the outer container from the child block in the container. If that make sence.
This works for the current item but what I like is if the flag is false then to check the outer container at this point programmatically. To see if a back grounds set.
Thank you for providing the example code.
I would still suggest using conditional CSS to change the inner colour if the outer colour is set.
If you want to make it more robust you can set a data attribute and use that as the condition in the CSS e.g. data-bg-set="true"
We need to add a an extra wrapper to each of the col if the outer (Parent) has a back color set. That then adds the correct positioning for the text.
I done this my adding code in to the block renderer that checks if the back color of the childs set and this works.
But I like to be able to check the row that each of the cols been rended in to see if that got a background color.
So I need to go back up the tree from area.cshtml to what areas.cshtml and know what called the area.cshtml from areas.cshtml.
Thouse this is a CSS issues at hart it also a settings issue on the block, I feel it needs to be addressed in area and areas .cshtml files and not in the CSS it self.
So again my Question is how can I see the parent block from the child block.
This code may show what I am trying to do, this works for current item in area.cshtml.
OK now I get it, you need to add a container based on whether the background colour is set.
I presume you need a container with padding etc when you add the background colour so the text doesn’t touch the edge or something similar.
Quick fix I have used many times is to create a variable that is set in the partial you check for the setting, then use viewdata to pass it to an if/else in the template.