I want to have links that activate a modal window with dynamic content and title. I would assume there is a way to do this with variables. I can do it now as a separate script for each modal, but is there a way to make it dynamic?
Links:
<a href="#" id="click-header">Modal 1</a>
<a href="#" id="click-header">Modal 2</a>
<a href="#" id="click-header">Modal 3</a>
<a href="#" id="click-header">Modal 4</a>
Modal Content
<div id="header-mpdal" style="display:none;">
<h3>TITLE 1</h3>
<p>CONTENT CONTENT 1</p>
</div>
<div id="header-mpdal" style="display:none;">
<h3>TITLE 2</h3>
<p>CONTENT 2</p>
</div>
<div id="header-mpdal" style="display:none;">
<h3>TITLE 3</h3>
<p>CONTENT 3</p>
</div>
<div id="header-mpdal" style="display:none;">
<h3>TITLE 4</h3>
<p>CONTENT 4</p>
</div>
Javascript
require(
[
'jquery',
'Magento_Ui/js/modal/modal'
],
function(
$,
modal
) {
var options = {
type: 'popup',
responsive: true,
innerScroll: true,
title: 'Dynamic Title',
buttons: [{
text: $.mage.__('Ok'),
class: '',
click: function () {
this.closeModal();
}
}]
};
var popup = modal(options, $('#header-mpdal'));
$("#click-header").on('click',function(){
$("#dynamic").modal("openModal");
});
}
);