pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Pug-PHP 3: Rendering files doesn't work the same way? #165

Closed wolfgang42 closed 7 years ago

wolfgang42 commented 7 years ago

I've upgraded to version 3 for testing, but passing file paths to $pug->render() seems to have stopped working. Here's a minimal test case:

<?php
require __DIR__.'/../vendor/autoload.php';
use Pug\Pug;
define('VIEWDIR', __DIR__.'/../views/');
$pug = new Pug([
    'basedir' => VIEWDIR,
]);
echo $pug->render(VIEWDIR.'/docs.pug');

This worked with 2.7 but simply echoes /var/www/html/../views//docs.pug on version 3. I don't see anything in the changelog about this; is there something I'm doing wrong?

kylekatarnls commented 7 years ago

Yes thanks, I will add it to the changelog, now you get 2 distinct methods: ->render for strings and ->renderFile for files. This is to be aligned on Pugjs.

kylekatarnls commented 7 years ago

I released 3.0.0-alpha5 that restore the ->render() pug-php 2 method. But I recommend to use the strict mode: https://github.com/pug-php/pug/blob/3.0.0-alpha5/MIGRATION_GUIDE.md#api-changes

When strict option is set to true, ->renderFile() only render files and ->render() only render strings, this follow the pugjs API and avoid unexpected behavior and magical tricky detections.

wolfgang42 commented 7 years ago

Thanks, splitting these functions makes much more sense than the old way of auto-guessing if it was a filename.