Hi, my friends!

I want to introduce you a new component in version 4.3.8 - Template. This component allows you to use javascript templates inside HTML elements.

Gif example

template-demo

Full code example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="../metro/css/metro-all.css?ver=@@b-version" rel="stylesheet">

    <title>Test Template - Metro 4 :: Popular HTML, CSS and JS library</title>
</head>
<body class="m4-cloak">
    <div class="container">
        <h1>Template test page</h1>

        <div class="mt-4 mb-4">
            <button class="button" onclick="$('.example').attr('data-template-data', 'webSkills')">Show Web skills</button>
            <button class="button" onclick="$('.example').attr('data-template-data', 'otherSkills')">Show Other skills</button>
        </div>

        <div class="example" data-role="template" data-template-data="webSkills">
            <h3>My skills</h3>
            <% if(this.showSkills) { %>
            <ul>
                <% for(var i = 0; i < this.skills.length; i++) { %>
                <li><% this.skills[i] %></li>
                <% } %>
            </ul>
            <% } else { %>
            <span>Nothing to show</span>
            <% } %>
        </div>
    </div>

<script src="../metro/js/metro.js?ver=@@b-version"></script>
<script>
    var webSkills = {
        skills: ["javascript", "html", "css"],
        showSkills: true
    };

    var otherSkills = {
        skills: ["php", "oracle", "mysql", "java", "pascal", "c/c++", "kotlin"],
        showSkills: true
    };
</script>
</body>
</html>
Last modified: 07.06.2020

Author

Comments

Write a Reply or Comment

Your email address will not be published.