Closed NatLuder closed 8 years ago
You can just use Jade and don't use any features that require dynamic functionality, Tale Jade tries to not include any PHP that it doesn't need (e.g. Mixins that aren't actually used or helper variables/functions that aren't needed anywhere)
Take a look at the Sandbox, they are directly rendered through Tale Jade. Some of the examples there don't generate any PHP, just plain HTML, since they don't use any dynamic features (control structures, variable-stuff etc.)
Notice that import/include
work and generate plain HTML, since they actually copy-and-paste, they don't fall back to PHP's include
.
In any other case, try to use the Stream
renderer (Set adapter
to stream
in the array you pass to the renderer). Notice that this requires allow_url_fopen
(maybe _It's allow_url_include
, I forgot, but I'll check it right now and update thisallow_url_fopen
. allow_url_include
can be off
_) set to on
in your php.ini
.
The Stream-Renderer doesn't need the caching-part, it renders HTML directly, there is no PHTML Output saved anywhere. It's not the default adapter just because of the damn php.ini setting requirement :(
A small example:
$renderer = new Tale\Jade\Renderer([
'adapter' => 'stream'
]);
$html = $renderer->render('some-jade-file');
//$html will be plain HTML, all dynamic features possible
Work's like a charm :)
If I am using it as in your given example I get an exception 🐹
Here goes my code:
$renderer = new Renderer([ 'adapter' => 'stream' ]); $html = $renderer->render($path.'template', array($defaults));
defaults are default values like: title: 'test', editable: false etc. path is the path to the template.jade
And the exception is: FatalErrorException in Pg== line 1: parse error
What am I missing?
P.S: the allow_url_fopen
is set to On
in my php.ini already (php 7.0)
Hmmm....that's not an exception that Tale Jade throws.
Try var_dump($renderer->compile($path.'template'))
first to see, if it compiles correctly.
I see three possible mistakes in your code (I don't know, maybe you wanted it like that)
array($defaults)
is probably wrong, you mostly want to just pass $defaults
, every key in $defaults
will be a variable inside the Jade template containing the value of that key.$path.'template'
looks somewhat wrong to me. If $path
is something like /your/view/folder/
(Notice the trailing slash) and it contains a file called template.jade
, then it might work.template.jd
or template.jade
It's probably better to use it like this:
$renderer = new Renderer([
'adapter' => 'stream',
'paths' => [$path]
]);
$html = $renderer->render('template', $defaults);
I'm running PHP7.0 with allow_url_fopen=on
and allow_url_include=off
and it works fine on my side.
Tell me if that helped you.
Also, maybe you can just show me your PHP and your Jade files :)
We also have Gitter now!
Closed as we talked about this on Gitter.
The problem was the fact that the Jade contained JavaScript-syntax and not PHP-syntax.
Hello, I am looking for a function which renders the given jade file into pure html and not phtml. Is there a possibility for this already and I haven't seen it yet? :)