Easier way to inject ad in preprocess function or render array

Created on 21 November 2018, about 6 years ago
Updated 9 January 2024, 12 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

Needs work

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.71.5 2024