jade-php
jade-php copied to clipboard
Variable in attribute
How to do this:
<a class="<?php echo $var; ?>"Google</a>
May be from this:
a(class=$var) Google
But don't work.
Thanks!
Slightly un-shorthand, but you can use eg.
a(foo!="<?php echo $bar ?>")
- ie. it will print the unescaped string "" in the attribute.
Also just found out that if you want to echo php directly into the tag (not in an attribute) you can use multiline format, eg:
a(foo!="" )
(second line should be indented)
EDIT: this seems to only work with a doctype declaration at top of file, eg. !!!5
It would be great if this functionality were built in.
+1, that would be a nice feature indeed
I have a better way:
Add a local variable into the compiler function wherever you have it, for example in gulp-jade you might find it inside:
gulp.src("some/src")
.pipe(jade({locals:{some:"value"}}))
This variable is going to be a function that can be called in all of your jade files. Lets focus on the jade function as seen above inside a pipe in that example.
JS new function:
jade(locals:{
$:function(str){
return "<?php print $"+str+" ?>"
}
})
JADE usage:
h1(class!=$(php_variable))
COMPILES
<h1 class="<?php print php_variable?>"></h1>