Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h2>JsRender Helpers Demo</h2>

<div id="result"></div>

<script id="theTmpl" type="text/x-jsrender">
<div>
   <em>Name:</em> {{toUpper:name}}
   {{if showNickname && nickname}}
      (Goes by <em>{{:nickname}}</em>)
   {{/if}}<br/>
   <em>Date of Birth:</em> {{formatDate:dob}} (<em>Age:</em> {{:~calcAge(dob)}})
   <br/>
   {{for address}}
    <div>
      <em>Address:</em> 
      {{:address1}}, 
      {{if address2}}{{:address2}}, {{/if}} 
      {{:city}}, 
      {{if provinceState}}{{:provinceState}}, {{/if}} 
      {{:postalCode}}
    </div>
  {{/for}}
</div>
</script>

<br/>
<br/>
<br/>
<br/>
<hr size="1" noshade color="#F00000">

<div style="font-size: 0.8em;">
<p>If you find this demo useful, please consider <a href="https://www.paypal.me/RobertGravelle/1" target="_blank">donating $1 dollar</a> for a coffee (secure PayPal link) or purchasing one of my songs from <a href="https://ax.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?term=rob%20gravelle" target="_blank">iTunes.com</a> or <a href="http://www.amazon.com/s/ref=ntt_srch_drd_B001ES9TTK?ie=UTF8&field-keywords=Rob%20Gravelle&index=digital-music&search-type=ss" target="_blank">Amazon.com</a> for only 0.99 cents each. I have also released CDs with my band <a href="https://www.cdbaby.com/Artist/IvoryKnight" target="_blank">Ivory Knight</a> and Annihilator main-man Jeff Waters.</p>
<p>Rob uses and recommends <a href="http://www.mochahost.com/2425.html" target="_blank">MochaHost</a>, which provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!</p>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                var names = [
  {
    "name": "Robert",
    "nickname": ["Blackjacques", "Rob"],
    "showNickname": true,
    "dob": "1969-01-14",
    "address": {
      "address1": "129 Reynolds St.",
      "address2": "unit 405",
      "city": "London",
      "provinceState": "",
      "country": "UK",
      "postalCode": "12345"
    }
  },
  {
    "name": "Jeanie",
    "nickname": "",
    "showNickname": false,
    "dob": "1968-06-12",
    "address": {
      "address1": "22 Accacia Ave.",
      "address2": "",
      "city": "Toronto",
      "provinceState": "Ontario",
      "country": "CA",
      "postalCode": "K2R 5S6"
    }
  }
];

var template = $.templates("#theTmpl");

$.views.helpers({
    calcAge: function(dob) {
      if (typeof(dob) == 'string') dob = new Date(dob);
     
      var dateToCalculate = new Date();
      var calculateYear   = dateToCalculate.getFullYear();
      var calculateMonth  = dateToCalculate.getMonth();
      var calculateDay    = dateToCalculate.getDate();
      
      var birthYear       = dob.getFullYear();
      var birthMonth      = dob.getMonth();
      var birthDay        = dob.getDate();

      var age      = calculateYear - birthYear;
      var ageMonth = calculateMonth - birthMonth;
      var ageDay   = calculateDay - birthDay;

      if (ageMonth < 0 || (ageMonth == 0 && ageDay < 0)) {
        age = parseInt(age) - 1;
      }
      return age;
    }
}, template);

$.views.converters("toUpper", function(val) {
   return val.toUpperCase();
});

$.views.converters("formatDate", function(val) {
  return (new Date(val)).toLocaleDateString('en-US', {
    day:   'numeric',
    month: 'long',
    year:  'numeric'
  });
});

var htmlOutput = template.render(names);

$("#result").html(htmlOutput);





              
            
!
999px

Console