While trying to fumble though getting the responsive tags to work on a new site, I ran across an issue on 8.x that I haven't seen on 7.x which is a new div with classes to encompass the google adsense code, however there are no classes appended...

Looking at adsense-ad.html.twig it "should" be working, but that's beyond my knowledge of why it isn't. It's also not spitting out "styles"?

adsense-ad.html.twig

{#
/**
 * @file
 * AdSense HTML wrapper.
 */
#}
<div class="{{ classes }}">
  <div class="adsense" style="{{ style }}">
    {{ content }}
  </div>
</div>

Actual Output Example

<section id="block-adsense" class="block clearfix ...">
  <div class="field field--name-body ...">
   <div class="responsive"><!-- my custom div -->
    <div class="">
     <div class="adsense" style="">
...

Any ideas why the classes and style isn't being output? Using Bootstrap 3.5 as the theme.

Comments

philsward created an issue. See original summary.

pmagunia’s picture

Not sure this helps, but adding CSS styles inline is not good programming practice. 'Inline' CSS is found on the page instead of a stylesheet.

Its best to use classes and stylesheets.

philsward’s picture

@pmagunia Not sure if it helps with this situation.

The twig code I referenced comes from the module. Not sure why it's trying to add inline styles, that's a maintainer question.

Still begs the question why the classes aren't being output at all though? They're... just... empty.

jcnventura’s picture

Title: Classes not being added? » Empty class and style attributes on ads

The reason why inline styles are used is because block dimensions are set accordingly to the ad dimension. And it is actually possible to have custom ad dimensions, which make it impossible to have a CSS class for all possible dimensions. Unless of course, I added 1 million classes to account for all possible variations of width and height between 1 and 1000px.

I've got no clue why classes and styles are not set in your case. Try to debug the template_preprocess_adsense_ad() function in adsense.module to check if those values are set correctly.

In any case, I'm changing the template slightly to not display empty class or style attributes.

  • jcnventura committed e6e3f67 on 8.x-1.x
    Issue #2882294 by jcnventura: Empty class and style attributes on ads
    
jcnventura’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.