pug-php / pug

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

Include doesn't work #125

Closed marcus-at-localhost closed 7 years ago

marcus-at-localhost commented 7 years ago

Hi, I installed the latest package (2.5.5) with composer onto my Windows/Xampp Test environment.

first I wasn't able to use this template (index.pug)

html5
  head
    title test
  body
    include content.pug
$this->pug = new Pug(array(
    'prettyprint' => true,
    'extension' => '.pug',
    'basedir' => $f3->get('TEMPLATE'),
    'cache' => false,
    'notFound' => false,
));

$output = $this->pug->render(
  file_get_contents($this->f3->get('TEMPLATE').'/index.pug'),
  $data
);

I always got that content.pug doesn't exist. Then I read that I have to call render with a file

$output = $this->pug->render(
  $this->f3->get('TEMPLATE').'/index.pug',
  $data
);

This didn't work either. index.pug didn't exist.

Finally I downgraded to 2.4 (because I had an app running with that version) and it finally worked.

Any idea?

kylekatarnls commented 7 years ago

$this->f3 vs. $f3 maybe, all tests passed and I just do this:

<?php

use Pug\Pug;

include __DIR__ . '/vendor/autoload.php';

$pug = new Pug(array(
    'prettyprint' => true,
    'extension' => '.pug',
    'basedir' => __DIR__ . '/template',
    'cache' => false,
    'notFound' => false,
));

$data = array();

$output = $pug->render(
    __DIR__ . '/template'.'/index.pug',
    $data
);

echo $output;

I get expected HTML:

<html5>
  <head>
    <title>test</title>
  </head>
  <body>Content</body>
</html5>

PS: html5 does not exists, you need doctype html then html here.

I did this with Pug 2.5.5, so I'm pretty sure, this is not the downgrad that solve your problem. Did you check what's out of $f3->get('TEMPLATE')?

marcus-at-localhost commented 7 years ago

The use of $this->f3 and $f3 was unclear in my example, but not the problem. I just updated to the latest version again and it worked. I checked my paths before and I'm sure it was correct, but that must have been the culprit. Probably a leading slash that I already changed. Thanks for your time looking into this.