Talesoft / tale-jade

A complete and fully-functional implementation of the Jade template language for PHP
http://jade.talesoft.codes
MIT License
88 stars 10 forks source link

Loading the converted Jade into html #93

Closed NatLuder closed 8 years ago

NatLuder commented 8 years ago

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? :)

TorbenKoehn commented 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 allow_url_include, I forgot, but I'll check it right now and update this _It's allow_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 :)

NatLuder commented 8 years ago

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)

TorbenKoehn commented 8 years ago

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)

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!

TorbenKoehn commented 8 years ago

Closed as we talked about this on Gitter.

The problem was the fact that the Jade contained JavaScript-syntax and not PHP-syntax.