Search results

Template

The Template property can be given as the HTML element; this can be either a string or query 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"
Source
Preview
index.js
index.html
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;
ele = document.createElement("button");
ele.textContent = "Show Toast"
ele.classList.add('e-btn');
ele.id = "show_toast";
document.body.appendChild(ele);

ele.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="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
    
    
<script src="//cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
      <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>

See Also