working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,399 snippets matching: templates

    public by cghersi  185245  1  6  1

    Use the Raw HTML content in XSLT transformations

    Usage of copy-of element allows to get the exact content of an XML node and put it as raw HTML, so that e.g. are not stripped out as instead happens with
    <myXmlNode>
    	<question>
    	Some text <br/> separated < br/> by new lines
    	</question>
    </myXmlNode>
    
    <span>
    	<xsl:copy-of select="question"/>
    </span>

    public by sTiLL-iLL @ SniPitz-KND  5166  4  9  42

    Vanilla KemPlates... MVC in stiches....

    real kwik model view controller example made with 100% vanilla JS
    
    ///  MY "SIGNALS" EVENT SYSTEM ////////////////
    
    //   this solution Uses my signals.js module
    
    ////////  styles  ///////////
    
    
    body {
    	font-family: Calibri;
    	width: 220px;
    }
    
    .container {
        border: 1px solid black;
        padding: 10px;
        width: 232px;
        margin: 50px auto 50px 350px;
    	border-radius: 7px;
    	background: lightgray;
    }
    
    fieldset {
    	width: 205px;
    	margin: 0 auto 3px 3px;
    	margin-right: auto;
    	margin-bottom: 6px;
    	padding: 10px;
    }
    
    h1 {
    	margin-left: 55px;
    	margin-right: auto;
    }
    
    span {
    	margin: 3px;
    }
    
    input {
    	margin-top: 2px;
    	margin-bottom: 8px;
    	width: 168px;
    	padding-left: 3px;
    }
    
    ul {
    	padding-left: 20px;
    	list-style: none;
    	color: navy;
    	overflow-x: hidden;
    }
    
    li {
    	max-width: 180px
    }
    
    
    
    /////////  Model(s)   ////////////////////////
    
    // this is the user model object
    
    var user1 = {
        name1: "Richard",
        name2: "Longwood",
        occupation: "Software Engineer",
        age: "40",
        title: 'Skillz Yo!',
        subTitle: "add a skill...",
        showSkills: true,
        skills: []
    };
    
    
    
    function UserModel (usr) {
        this.user = usr;
        this.get = function(k) {
            if (k) {
                var u = this.user;
                return u[k];
            } 
            else {
                var u = this.user;
                return u;
            }
        };
    };
    
    
    
    var User = new UserModel (user1);
    User.prototype = Signals;
    User.constructor = User;
    
    User.on = function(v, cbk) {
        this.prototype.receive(v, function(d) {
            cbk.call(this.user, d);
        });
    };
    User.emit = function(v) {
        this.prototype.signal("change", v);
    };
    User.off = function(v) {
        this.prototype.dropReceivers(v);
    };
    User.set = function(k, v) {
        if (v && v !== this.user[k]) {
            if (k == "skills") {
                this.user[k].push(v);
            } else {
                this.user[k] = v;
            }
            this.prototype.signal("change", this.user);
        }
    };
    
    
    
    // array for template strings, 
    // our template engine, and an array of target Ids.
    
    var kList = [], 
        TPE = new TPEngine(), 
        Nodz = ["t1", "t2", "t3", "t4", "t5", "t6"];
    
    
    
    // this template string is pretty bulky, 
    // so Ill keep it stashed as a string, 
    // then inject it into its target when its time.
    
    var template6 = '~>{ if(User.get("showSkills")) { :}' + 
            '~>{ for(var index in User.get("skills")) { :}' + 
            '<li><a href="#"> ~>{ User.get("skills")[index] :}' + 
            '</a></li> ~>{ } :}' + '~>{ } else { :}' + 
            '<li>none</li>' + '~>{ } :}';
    
    
    
    // this array holds the template strings.
    // the innerText is where I extract them from the mark-up
    // notice how #5 is already defined
    
    var Templates = [
        template1 = t1.innerText, 
        template2 = t2.innerText, 
        template3 = t3.innerText, 
        template4 = t4.innerText,
        template5 = t5.innerText, 
        template6
    ];
    
    
    // Now I iterate over the list of nodes and templates,
    // pull each one out per the array position and plug
    // them into the kompiler along with the property of the node that 
    // the content is assigned to, then komile into a "kPlate" template.
    // each one of these kPlates is then put into another array: "kList"
    
    Nodz.forEach(function(tmpltNd) {
        var seed = Templates.shift();
        kPlt = TPE.Template(tmpltNd, "innerHTML", seed);
        kList.push(kPlt);
    });
    
    
    
    // Here, we set up the 2-way bindings
    
    var bb = document.getElementById("btn"), 
        tgl = document.getElementById("tgl"),
        updateDom = function (d) {
            kList.forEach(function(itm) {
                TPE.BindSet(itm, d);
            });
        },
        updateModel = function (d) {
            User.set("skills", tgl.value);
            tgl.value = "";
        };
    
    
    // When the button is pressed, this handler
    // in the controller hears it, grabs the new value
    // and updates the model.
    
    bb.addEventListener("click", updateModel);
    
    
    // When the model's value is changed, it fires a change event.
    // The handler here in the controller hears it,
    // grabs the new value, and then updates the dom
     
    User.on("change", updateDom);
    
    
    // This part basicly is what runs on window ready.
    // Now that everything is all set up..
    // we iterate over the array of kPlates that we stored earlier,
    // calling BindSet on each one. This renders the mark-up
    // to the dom at lightening speed, and there ya go!
    
    kList.forEach(function(itm) {
        TPE.BindSet(itm, User);
    });
    
    
    
    
    
    
    //////////// Template kompiler (controller)  //////////////////////////////////////
    
    this.TPEngine = function() {
        var kompiler = function(templateString, model) {
            var rgx = /~>{([^:]+)?:}/g, 
            rgex = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, 
            segment = 'var r=[];\n', position = 0, 
            kompile = function(chunk, ixjs) {
                ixjs ? (segment += chunk.match(rgex) ? chunk + '\n' : 'r.push(' + chunk + ');\n') : 
                (segment += chunk != '' ? 'r.push("' + chunk.replace(/"/g, '\\"') + '");\n' : '');
                return kompile;
            };
            while (match = rgx.exec(templateString)) {
                kompile(templateString.slice(position, match.index))(match[1], true);
                position = (match.index + match[0].length);
            }
            ;
            kompile(templateString.substr(position, templateString.length - position));
            segment += 'return r.join("");';
            return new Function(segment.replace(/[\r\t\n]/g, '')).apply(model);
        }, 
        template = function(elementID, prop, templateString) {
            var c = {
                tStr: templateString,
                tProp: prop,
                tVal: document.getElementById(elementID)
            };
            return c;
        }, 
        applyBind = function(temp, model) {
            if (temp.tVal.id && temp.tStr && model) {
                template = temp;
                var el = document.getElementById(template.tVal.id);
                el[template.tProp] = kompiler(template.tStr, model);
                template.tVal = el;
            }
        };
        return {
            Template: template,
            BindSet: applyBind
        };
    };
    
    
    ///////// VIEW  //////////////////////////
    
    <!DOCTYPE html>
    <html>
    <head>
    	<title>MY MVC</title>
    </head>
      	<meta charset="utf-8" />
    	<link rel="stylesheet" href="css/stylz.css" />
    	<script src="js/signals.js"></script>
    	<script src="js/myTPlates.js"></script>
    <body>
    	<div class="container">
    		<h1 id="t1">
    			~>{ User.get("title") :} 
    		</h1>
    		<fieldset>
    			<legend id="t2">
    				~>{ User.get("subTitle") :}
    			</legend>
    			<input id="tgl" type="text" placeholder="skills"></input>
            	<button id="btn">+</button>
    			<hr><b>
    			  Name:
    			  <span id="t3">
    					~>{ User.get("name1") +" "+ User.get("name2") :}
    			  </span>
    			  </br>
    			  Age: 
    			  <span id="t4">
    					~>{ User.get("age") :}
    			 </span>
    			 </br>
    			  Dept: 
    			  <span id="t5">
    					~>{ User.get("occupation") :}
    			 </span>
    			 <hr>
    			  Skills List: 
    			 <ul id="t6">
    					~>{ User.get("skills") :}
    			 </ul></b>	
    			<hr>
    		</fieldset>
    	</div>
    </body>
    <script src="js/script1.js"></script>
    </html>
    
    
                                                                                                                

    public by micurs  4303  1  7  3

    Defininig arrays using templates in Typescript

    You can now define an array using the template feature in Typescript. Be aware this way to build array is just a compile time 'type annotation' used to check type validity when using the array.
    class MyItemClass {
      ...
    }
    
    // Define an array for MyItemClass
    var itemArray : Array<MyItemClass>;
    ...
    
    var item : MyItem = itemArray[3];
    

    public by Casper  4036  0  7  3

    foreach construct in XSLT templates

    Simple example of a for each construct
    <xsl:for-each select="myXMLElem" >
      <div>
        <xsl:text disable-output-escaping="yes">&amp;raquo;&amp;nbsp;</xsl:text>
        <a style="text-decoration: none; margin-left:0.5em;">
          <xsl:attribute name="href">
            <xsl:value-of select="@myAttrInXMLElem"/>
          </xsl:attribute>
          <span><xsl:value-of select="@anotherAttr"/></span>
        </a>
      </div>
    </xsl:for-each>

    public by Crater  2805  0  6  0

    Usage of choose operator in XSLT

    This is a simple yet common use of choose operator for templates
    <xsl:choose>
      <xsl:when test="@RefersTo = 'Value'"> some normal text</xsl:when>
      <xsl:otherwise>
        <a style="text-decoration: none;">
          <xsl:attribute name="href">
            <xsl:value-of select="@myurl"/>
          </xsl:attribute>
          <span> another text in the hyperlink</span>
        </a>
      </xsl:otherwise>
    </xsl:choose>

    public by Geometry  1225  0  7  0

    Transpose: Gets the transpose of a matrix.

    TODO: Use T4 templates for the equality comparisons Gets the transpose of a matrix. A matrix. True to store the transpose over the same input , false otherwise. Default is false. The transpose of the given matrix.
    /// <summary>
    ///   Gets the transpose of a matrix.
    /// </summary>
    /// 
    /// <param name="matrix">A matrix.</param>
    /// 
    /// <param name="inPlace">True to store the transpose over the same input
    ///   <paramref name="matrix"/>, false otherwise. Default is false.</param>
    ///   
    /// <returns>The transpose of the given matrix.</returns>
    /// 
    public static T[][] Transpose<T>(this T[][] matrix, bool inPlace)
    {
        int rows = matrix.Length;
        if (rows == 0) return new T[rows][];
        int cols = matrix[0].Length;
    
        if (inPlace)
        {
            if (rows != cols)
                throw new ArgumentException("Only square matrices can be transposed in place.", "matrix");
    
            for (int i = 0; i < rows; i++)
            {
                for (int j = i; j < cols; j++)
                {
                    T element = matrix[j][i];
                    matrix[j][i] = matrix[i][j];
                    matrix[i][j] = element;
                }
            }
    
            return matrix;
        }
        else
        {
            T[][] result = new T[cols][];
            for (int j = 0; j < cols; j++)
            {
                result[j] = new T[rows];
                for (int i = 0; i < rows; i++)
                    result[j][i] = matrix[i][j];
            }
    
            return result;
        }
    }

    public by Percival  3220  0  6  1

    Usage of xsl:if operator in XSLT

    Simple yet effective example of xsl:if condition in templates and transformations
    <span style="color:ff8500;">
      <xsl:if test="@RefersTo = 'SomeValue'">
        <xsl:value-of select="@MyAttr"/>
      </xsl:if>
    </span>

    public by robedgar  1735  1  5  0

    regex to find panel without a sizing class

    regex for webstorm ide to find templates containg a panel with a missing size class
    <panel(?:(?!narrow|medium|wide)[^>])+>

    public by paulsimmons  1117  0  5  0

    Magento Follow Up Emails Extension

    Magento Follow Up Email is a complete extension developed by FMEAddons that allows store owners to integrate and advance email marketing system in their online store based on Magento. With the help of this powerful extension, they can send emails after occurring of different events such as new order completion, Cart abandonment, Birthday, Christmas
    // Enter here the actual content of the snippet.                        

    public by simonwalker  215  1  5  0

    Magento 2 Responsive E-Mail Template Extension By FME

    Magento 2 Email Templates extension helps you customize emails for better communication with the buyers and users of your eCommerce website. With 3 different themes, you can choose an appealing layout and design for the transactional emails. Magento email templates sets you free to select between Blue Lagoon, Black and Red Tux, and Orange Peak whic
    // Enter here the actual content of the snippet.						
    • Public Snippets
    • Channels Snippets