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


Full code example

<!DOCTYPE html>
<html lang="en">
    <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>
<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 class="example" data-role="template" data-template-data="webSkills">
            <h3>My skills</h3>
            <% if(this.showSkills) { %>
                <% for(var i = 0; i < this.skills.length; i++) { %>
                <li><% this.skills[i] %></li>
                <% } %>
            <% } else { %>
            <span>Nothing to show</span>
            <% } %>

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

    var otherSkills = {
        skills: ["php", "oracle", "mysql", "java", "pascal", "c/c++", "kotlin"],
        showSkills: true
Last modified: 07.06.2020



Write a Reply or Comment

Your email address will not be published.