0
votes

On every pageview of a certain content type within Drupal (8) I need to get a new (unique) token from an external webservice to be able to embed a certain mediafile by using this token in the javascript embed code. This token needs to be called from the webserver (curl), not on the client side.

This works ok within Drupal by adding a theme_preprocess_node function within the theme file - but because of the caching within Drupal/Twig this token won't get refreshed each pageview, only when the cache is emptied. Totally disabling the cache is not preferred - neither is using an AJAX call requiring the use of a synchronous call.

Does anybody have an idea on getting the value of the external webservice in the Twig template?

1

1 Answers

0
votes

I found the solution to my problem by adding

$variables['#cache']['max-age'] = 0;

to theme_pre_process_node. This will keep the variables generated out of the cache.