File: examples/callback-example.html

Recommend this page to a friend!
  Classes of Diego La Monica  >  Xtemplate  >  examples/callback-example.html  >  Download  
File: examples/callback-example.html
Role: Example script
Content type: text/plain
Description: Example
Class: Xtemplate
Template engine that uses HTML page fragments
Author: By
Last change: V 1.4.1
- Updated examples
Date: 6 years ago
Size: 5,368 bytes


Class file image Download
<!DOCTYPE html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Callback usage example</title>
    <script type="text/javascript" src="//"></script>
    <script src="//"></script>
    <script type="text/javascript" src="../xtemplate.js"></script>
    <script src=""></script>

    <link rel="stylesheet" href="">
        div#example {
            border-radius: 10px;
            border: 2px dashed #ddd;
            margin: 1em;
            padding: 1em;

    <script type="text/x-template" id="country-template">
        and I am from {$country}
    <script type="text/x-template" id="name-template">
        <div class="row">
            <div class="col-md-12">
                Hello, my name is {$name}

    <div class="container">

        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <a class="navbar-brand" href="./">XTemplate</a>
                <p class="navbar-text">Using callback</p>

            </div><!-- /.container-fluid -->

        <div class="row" id="example">
            <div class="col-md-12" id="my-section">
                This text will be replaced

        <div class="row">
            <div class="well well-lg">

                <h1>Did you enjoyed this example?</h1>
                    Producing this library and an example like this, bring me a lot of time away from me, so I need to
                    know how much this library is of community interest to program its evolutions, updates and upgrades.
                    Then I'm asking you to perform 3 simple things to demonstrate your interest:
                    <li><a target="_blank" href="">Star</a> (and watch) this library on GitHub</li>
                    <li><a target="_blank" href="">Follow me</a> on Twitter</li>
                    <li>Add a like to <a target="_blank" href="">my Facebook page</a></li>


        <!-- Source code viewer -->
        <ul class="nav nav-tabs">
            <li class="active"><a href="#js-code" data-toggle="tab">Javascript</a></li>
            <li><a href="#xt-code" data-toggle="tab">Templates</a></li>
        <div class="tab-content">
            <div class="tab-pane active" id="js-code"><pre class="sh_javascript" id="js"></pre></div>
            <div class="tab-pane" id="xt-code"><pre class="sh_html" id="xt"></pre></div>
        <!-- End source code -->


    <script type="text/javascript" id="source-code">
        function showExample() {
            function myDataCallback(row) {

                var names = {
                    John: 'London',
                    Aaron: 'New York City',
                    Anita: 'Spain'

                if (names[] !== undefined) {
           = names[];
                return row;

            var x = new Xtemplate(),
                    rows = [
                        {name: 'Diego', country: 'Italy'},
                        {name: 'John'},
                        {name: 'Aaron'},
                        {name: 'Anita'}
                    output = x.apply('#name-template', rows, myDataCallback);


    <link rel="stylesheet" type="text/css" href="" />
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>

        SourceViewer.createDisplayArea(null, 'xt',
                SourceViewer.getSource('#country-template',true) + "\n\n" +
        SourceViewer.createDisplayArea(null, 'js', '#source-code');


    <a href=""><img style="position: fixed; top: 0; right: 0; border: 0;" src="" alt="Fork me on GitHub" data-canonical-src=""></a>