-1

Not sure I'm wording this right so please forgive me. I'm working on a situation where I want to apply the background to the 1st NON .container ancestor of my current module. So, for example..

<div id="testimonials">
    <div class="container">
        <div class="row">
            <div class="moduletable bear">

I would want to apply the background to the "testimonials" id. the problem is the structure could look 4 different ways.

<div class="testimonials">
    <div class="container">
        <div class="row">
            <div class="moduletable bear">

or

<div id="testimonials">
    <div class="container">
        <div class="moduletable bear">

or

<div id="testimonials">
    <div class="row">
        <div class="moduletable bear">

or

<div id="testimonials">
    <div class="moduletable bear">

I have no way of knowing from inside the module as it would depend on the template and module position structure.

what I THINK I need is something like..

if($parent == 'row') {
   if($grandparent == 'container'){
     $backgroundClass = $greatgrandparent;
    } else {
    $backgroundClass = $grandparent;
    }
elseif($parent == 'container'){
 $backgroundClass = $grandparent
} else {
$backgroundClass = $parent;
}

How can I get this to work? The use case is to apply a background to the 1st NON-containered parent. This is for bootstrap 3 if that makes a difference.

  • I don't think I follow what kind of solution you need. If you are looking for a css solution, you might entertain styling all dom elements with your background, then clearing that style declaration for the .container elements and all of its children. However, you are showing php, so... do you want to parse and adjust the DOM before printing it to screen? Maybe I need to see clarification on the different scenarios and your desired effect. – mickmackusa Dec 6 '19 at 12:29
  • Can you not use pure css? #testimonials, .testimonials { // your styles } ? This will target the testimonial elements by id or class. Maybe I need more clarity. – mickmackusa Dec 7 '19 at 2:40
  • Or it could be solved with providing a short javascript/jQuery script with your module layout that can check the structure like if (element.parent) {...} then the div background is this or that... you could find and create these simple scripts... – Zollie Dec 7 '19 at 17:01
0

Ummm. PHP code inside a module has no access to nor knowledge of the markup that will eventually be wrapped around it. There's no telling what chrome a template override may put in place, and the module actually gets rendered before it does, so at the time the module PHP gets executed, the markup wrapping the module has yet to be determined.

I can't imagine a circumstance that makes something like what I think you're trying to do a good solution to a problem (it's the sort of thing that will affect far more than just your module, which makes it dubious) but if it's the only way to solve your problem, your best course is to write a short javascript function that will walk the DOM up from your module to find the right element to work on. If the javascript needs access to information the PHP has, use the PHP to write the javascript, so it can put that data into javascript variables.

| improve this answer | |
  • Yes, perhaps an XY problem. – mickmackusa Dec 7 '19 at 2:35
  • ok, ty @arlen, seem's its going to be more trouble then to simply "fix" the poorly coded section of the module to begin with. I wasn't aware the module is laid out before the template layout was. Walking it back up was exactly what I was thinking & quite frankly with the numerous possible <div><div> possibilities it seemed wrong but I didn't see another way. I'll find another solution... THANKS – Troy Hall Dec 7 '19 at 3:34
  • You might be able to override the module's markup with a template override or some chrome of your own. Not enough knowledge of the specifics to give you detailed advice, but if writing some module Chrome of your own isn't a possibility, look for a "tmpl" folder in the module code. Anything that's in that can be overridden in the template. – Arlen Dec 12 '19 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.