Skip to content

A super simple way to include HTML in other HTML pages (like Server Side Includes for Apache)

Notifications You must be signed in to change notification settings

joshbirk/SnipJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Snip

Snip is a ridiculously simple Node module to include client side files into other files (essentially the same as Server Side Includes with Apache). There might be, and probably are, other modules which include this functionality and a lot more - but I needed it for some demo code, was curious if I could get it to work in a couple hours as an experiment ... so here it is.

To install: fork or download this code and the "require" to the directory. Or you can npm install snip (this project is also my testing ground for NPM modules).

To use:

  1. After installing, add "require('snip')"
  2. Create a root level directory called "snips".
  3. Place HTML in "snips" you want to include into other pages.
  4. Place comments in the HTML you want to have the snips included in like this:
    <!-- snip:html/header.html -->
    While keeping the spacing the same as above, this comment would bring "header.html" from the "html" directory in "snips" to the page.
  5. In where you are routing HTML, "snip" incoming data. Like so:
    <P>
    fs.readFile('views/index.html', 'utf8', function(err, data){<BR />
    	res.writeHead(200, {'Content-Type':'text/html'});  <BR />
    	res.write(snip.snip(data));  <BR />
    	res.end();<BR />
    	});<BR />
    </P>
    
    
    </LI>
    

That's it. Catch me on twitter @joshbirk if you have any questions.

Todo:

  • Make the "snips" directory controlled by environment variables.
  • Make snips multi-level.

About

A super simple way to include HTML in other HTML pages (like Server Side Includes for Apache)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published