pug-php / pug

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

Uncaught Error: Call to undefined function asset() in pug.stream #159

Closed MarcelRobitaille closed 7 years ago

MarcelRobitaille commented 7 years ago

When I run the following code:

require_once './vendor/autoload.php';

$pug = new \Pug\Pug([
  'extension' => 'pug',
]);
$pug->render('./views/home.pug');

I get the following stack trace:

[Thu Sep 21 14:13:36 2017] 127.0.0.1:54454 [500]: / - Uncaught Error: Call to undefined function asset() in pug.stream://data;<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"<?php $__classes = implode(" ", array_unique(array_merge(empty($__classes) ? array() : explode(" ", $__classes), array (
), array())) ); ?><?php if (!empty($__classes)) { echo ' class="' . $__classes . '"'; } unset($__classes);  ?>><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"<?php $__classes = implode(" ", array_unique(array_merge(empty($__classes) ? array() : explode(" ", $__classes), array (
), array())) ); ?><?php if (!empty($__classes)) { echo ' class="' . $__classes . '"'; } unset($__classes);  ?>><link rel="stylesheet"<?php if (true === ($__value = asset("/public/css/global.css"))) {  ?> href<?php } else if (\Jade\Compiler::isDisplayable($__value)) {  ?> href="<?php echo \Jade\Compiler::getEscapedValue($__value, '"') ?>"<?php } ?><?php $__classes = implode(" ", array_unique(array_merge(empty($__classes) ? array() : explode(" ", in pug.stream://data;<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"<?php $__classes = implode(" ", array_unique(array_merge(empty($__classes) ? array() : explode(" ", $__classes), array (
), array())) ); ?><?php if (!empty($__classes)) { echo ' class="' . $__classes . '"'; } unset($__classes);  ?>><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"<?php $__classes = implode(" ", array_unique(array_merge(empty($__classes) ? array() : explode(" ", $__classes), array (
), array())) ); ?><?php if (!empty($__classes)) { echo ' class="' . $__classes . '"'; } unset($__classes);  ?>><link rel="stylesheet"<?php if (true === ($__value = asset("/public/css/global.css"))) {  ?> href<?php } else if (\Jade\Compiler::isDisplayable($__value)) {  ?> href="<?php echo \Jade\Compiler::getEscapedValue($__value, '"') ?>"<?php } ?><?php $__classes = implode(" ", array_unique(array_merge(empty($__classes) ? array() : explode(" ", $__classes), array (
), array())) ); ?><?php if (!empty($__classes)) { echo ' class="' . $__classes . '"'; } unset($__classes);  ?>></head><body></body></html> on line 3

I get that for some reason the asset() function is missing, but after googling for a while I haven't been able to find any information on the function at all let alone the error.

I installed the plugin as described in the README using composer.

php: 7.1.9 composer: 1.5.2

Sorry if this is a dumb question. I am being forced to use php and am not very good at it.

kylekatarnls commented 7 years ago

I suppose your template (home.pug) contains an asset call, if this function is not declared, this failure is expected.

If you try to use the asset function of Symfony, you should first install symfony then https://github.com/pug-php/pug-symfony

Else, please provide your template.

MarcelRobitaille commented 7 years ago

You are right. I am stupid. I copied the template from a node.js app where asset was defined. Sorry for wasting your time.