_$variables['is_front'
_]を_template_preprocess_page()
から_Drupal8
_のjqueryスクリプトに渡すにはどうすればよいですか?
それを送る:
function mytheme_preprocess_page(&$variables) {
$variables['#attached'] = [
'drupalSettings' => [
'myLibrary' => [
'is_front' => $variables['is_front'],
],
],
];
}
jqueryでそれにアクセスします:
Drupal.behaviors.myBehaviour = {
attach: function (context, settings) {
console.log(settings.myLibrary.is_front);
}
};