You are here

dfp-slot-definition-js.html.twig in Doubleclick for Publishers (DFP) 8

Default theme implementation to display a DFP short tag.

Available variables:

  • tag: TagView object for a DFP tag.

See also

\Drupal\dfp\View\Tag\TagViewBuilder::buildPreTag()

File

templates/dfp-slot-definition-js.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a DFP short tag.
  5. *
  6. * Available variables:
  7. * - tag: TagView object for a DFP tag.
  8. *
  9. * @see \Drupal\dfp\View\Tag\TagViewBuilder::buildPreTag()
  10. *
  11. * @ingroup themeable
  12. */
  13. #}
  14. <script type="text/javascript">
  15. {% if tag.breakpoints %}
  16. // Start by defining breakpoints for this ad.
  17. var mapping = googletag.sizeMapping()
  18. {% for breakpoint in tag.breakpoints %}
  19. .addSize({{ breakpoint.browser_size }}, {{ breakpoint.ad_sizes }})
  20. {% endfor %}
  21. .build();
  22. {% endif %}
  23. googletag.slots["{{ tag.id }}"] = googletag.defineSlot("{{ tag.adUnit }}", {{ tag.size|raw }}, "{{ tag.placeholderId }}")
  24. {% if tag.clickUrl %}
  25. .setClickUrl("{{ tag.clickUrl }}")
  26. {% endif %}
  27. .addService(googletag.pubads())
  28. {% if tag.adsenseAdTypes %}
  29. .set('adsense_ad_types', '{{ tag.adsenseAdTypes }}')
  30. {% endif %}
  31. {% if tag.adsenseChannelIds %}
  32. .set('adsense_channel_ids', '{{ tag.adsenseChannelIds }}')
  33. {% endif %}
  34. {% for key, color in tag.adSenseColors %}
  35. .set('adsense_{{ key }}_color', '#{{ color|upper }}')
  36. {% endfor %}
  37. {% for target in tag.targeting %}
  38. .setTargeting('{{ target.target }}', [
  39. {%- for value in target.value -%}
  40. '{{ value }}'{%- if not loop.last -%},{%- endif -%}
  41. {%- endfor -%}
  42. ])
  43. {% endfor %}
  44. {% if tag.breakpoints %}
  45. // Apply size mapping when there are breakpoints.
  46. .defineSizeMapping(mapping)
  47. {% endif %}
  48. ;
  49. </script>