Skip to main content

CMS Recipes

WordPress

add_action( 'wp_head', function () {
if ( ! current_user_can( 'administrator' ) ) {
echo '<script>window.PTP_CONFIG = { targetElementSelector: "main" };</script>';
echo '<script src="https://api.participaite.de/static/'. esc_attr( $client_id ) .'/ptpSimplify.js" defer></script>';
}
});

TYPO3 (TypoScript)

page.includeJSFooter.ptpSimplify = https://api.participaite.de/static/{{client_id}}/ptpSimplify.js
page.includeJSFooter.ptpSimplify.external = 1
page.includeJSFooter.ptpSimplify.defer = 1

page.headerData.100 = TEXT
page.headerData.100.value ( <script>window.PTP_CONFIG = { targetElementSelector: 'main' };</script> )

Drupal 9/10

Create ptp_simplify.libraries.yml:

ptp_simplify:
remote: https://api.participaite.de/static/{{client_id}}/ptpSimplify.js
version: 1.x
attributes:
defer: true

Attach in yourtheme.theme:

function yourtheme_preprocess_html(&$vars) {
if (!\Drupal::currentUser()->hasPermission('administer site configuration')) {
$vars['#attached']['html_head'][] = [[ '#tag' => 'script', '#value' => 'window.PTP_CONFIG = { targetElementSelector: "main" };' ], 'ptp_config'];
}
}

And in page.html.twig:

{{ attach_library('ptp_simplify/ptp_simplify') }}