Socket
Socket
Sign inDemoInstall

append-template

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    append-template

A jQuery plugin that lets you insert a file into the DOM, after defining variables to be added within the file.


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Sick of appending large chunks of HTML from your scripts? I am.

// Ew.
$(".sidebar").append("<div class='inner-wrapper'><div class='heading'>Welcome, " + username + "!</div><div class='about'>They're from " + country + ".</div></div>");

Introducing: .appendTemplate()

.appendTemplate is a jQuery plugin that lets you insert a file into the DOM, after defining variables to be added within the file. Check it out...

<!-- index.html -->
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="appendTemplate.jquery.min.js"></script>

<div class="container"></div>

<script type="text/javascript">
  $(".container").appendTemplate("templates/user_profile.html", {username: "@adammcarth", country: "Australia"});
</script>
<!-- templates/user_profile.html -->
<h1>Welcome, {{username}}!</h1>
<p>They come from {{country}}.</p>

Usage

appendTemplate( file_location, variables, callback, prepend );

Set the final argument of the function to true to prepend instead of append.

Local File System Warning

Most browsers won't allow you to open files from your local system, so if you're developing without a web server (just in plain HTML), you could run into some troubles. Google chrome users can try starting chrome with --allow-file-access-from-files. Read more: http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-allow-origin-for-file

Contributing

Contributions are always welcome:

  1. Fork this repository.
  2. Create a new branch: git checkout -b my-new-feature
  3. Minify your changes using an online compressor of your choice.
  4. Send in a pull request!

Keywords

FAQs

Last updated on 08 Apr 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc