Easier way to inject ad in preprocess function or render array

Created on 21 November 2018, over 5 years ago
Updated 6 February 2024, 5 months ago

If you need to inject an ad into a node body in a preprocess function, the easiest way of doing it seems to be by creating an instance of a block which uses a long uuid in the name.

$block = \Drupal::service('plugin.manager.block')->createInstance('dfp_ad:06c992b5-c864-4b6b-ba7e-d5304330720d');

$vars['ad'] = $block->build();

It would be great if you could could use a render element with the machine name (which is easier to remember), like this:

$vars['ad'] = [
  '#type' => 'dfp_tag',
  '#tag' => 'two_thirds_zone',
];
✨ Feature request
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States oknate Greater New York City Area

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024