jade-php
jade-php copied to clipboard
In-line javascript code
I really like this template engine, I think you have done a great job. I wanted to replace smarty with jade in a php framework I have developed. I am now using jade-php with grunt to compile the templates to phtml files for display within the framework. That is all working very nicely. However, I also wanted the ability to set compile time JS variables to control things like active menu options. To this end, I have added support for '>' to indicate in-line javascript. Let me explain what I mean:
//- layout/master.jade
//- Example inline php
- $test = '1234';
//- Example compile-time config variables
> test = 100;
isJade = true;
homePage = ['home', '/home.html'];
blogPage = ['blog', '/blog.html'];
portfolioPage = ['portfolio', '/portfolio.html'];
currentPage = homePage[1];
title = 'Example';
//- Read config variables from page extension
block config
For example, the page extension file would be something like: //- blog.jade extends layout/master.jade block config > currentPage = blogPage[1]; title = title + ' - Blog Page';
This allows me to reference the javascript variables with normal jade syntax e.g.
title #{title}
+navbar([homePage, blogPage, portfolioPage], currentPage)
if (isJade)
p Well done, you are using Jade :-)
else
p Shame on you, you are not using Jade!
p.
This way is shortest if you need big #{test}
blocks of text spanning multiple
lines.
The amount of code change in compiler.js is very small and does not affect any existing functionality. Is this something you would be interested in incorporating into your repo ? Obviously my interest is a selfish one, I would much rather benefit from your updates than maintain my own fork ;-)