我正在面對表單API中的「#markup」問題。在drupal中使用窗體8
在Drupal 7的,我們可以用它看起來像這樣「#markup」表單元素:
<?php
$form['test'] = array(
'#type' => 'markup',
'#markup' => '<div><script src="http://localhost/drupal7/sites/all/libraries/test.js"></script></div>',
);
?>
//Here is my custom test.js
(function($) {
Drupal.behaviors.test = {
attach: function(context, settings) {
console.log('testttt');
document.write('*Hello, there!*');
}
};
})(jQuery);
和上面的代碼將打印表格時,將呈現「您好,有!」。
現在在Drupal 8我使用下面的代碼,但它什麼都不打印。
<?php
$form['test'] = array(
'#markup' => '<div><script src="http://localhost/project8/sites/all/libraries/test.js"></script></div>',
);
?>
那麼如何在已經在Drupal 7中工作的Drupal 8中實現這個功能。 在script標籤也可以是本地腳本或外部腳本.. 請幫助...
感謝
謝謝它的作品! – rishabh318