M
M
marrs2016-04-28 19:26:19
Drupal
marrs, 2016-04-28 19:26:19

(Drupal 8) How to get value (not array, but string?html) of custom field in theme_preprocess_node?

Save gentlemen!
I am familiar with Drupal for the first day, and immediately started with 8.
There is a content_type and a custom_field is attached to it.
Task:
In the standard field of the wysiwyg editor, the shortcode [my_field] is inserted, it is necessary that on the front, instead of this shortcode, the created my_custom_field is displayed.
I output it in the node--theme-page.html.twig file.
I cling to the hook theme_preprocess_node.
I need something like this, but to work)

function mytheme_preprocess_node(&$variables) {
  
  $variables['content']['body'] = str_replace('[my_field]', $variables['content']['my_custom_field'], $variables['content']['body']);

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question