Template in EJ2 JavaScript Toast control
10 May 20234 minutes to read
The Template property in toast can be defined as HTML element
, this can be either a string
or selector
.
The HTML element tag can be given as a string for the Template property.
template: "<div>Toast Content</div>"
The Template property allows getting the template content using the query selector
. Here, the element ‘ID’ attribute is specified in the template.
template: "#Template"
ej.base.enableRipple(true);
//Initialize Toast component
var toast = new ej.notifications.Toast({
template: document.getElementById('template_toast_ele').innerHTML,
position: { X: 'Right', Y: 'Bottom' },
target: document.body,
extendedTimeout: 0,
timeOut: 120000,
});
//Render initialized Toast component
toast.appendTo('#element');
toast.show();
var btnEle = document.getElementById('toast_mail_remainder');
var snoozeFlag = false;
document.getElementById('show_toast').onclick = function () {
toast.show();
};
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 Toast</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Toolbar Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div class="row"> <button class="e-btn" id="show_toast"> Show Toast</button> </div>
<div id="template_toast"> <div id="element"></div> </div>
<br><br>
<div id="result"></div>
</div>
<script id="template_toast_ele" type="text/x-template">
<div id='template_toast' style="display: none">
<div class="horizontal-align">
<div class='toast-content'>
<div class='toast-title'>
Weekend Alarm
</div>
<div class='toast-message'> With traffic, its likely to take 45 minutes to get to jenny's 24th Birthday Bash at Hillside Bar, 454 E.
Olive Way by 10:00PM </div>
</div>
</div>
<img src="https://ej2.syncfusion.com/demos/src/toast/resource/map.jpg" width="100%" height="70%">
</div>
</script>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>