pug-php / pug

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

Error response in pug template #203

Closed Freest10 closed 6 years ago

Freest10 commented 6 years ago

Hello, I call the php method inside a pug template and I want that server to answer me 400 code with json in a pug template, how can I do this? header and the http_response_code php methods cause a template error.

Thanks!

kylekatarnls commented 6 years ago

Inside the template, you can do:

- header('Status: 404 Not Found');
| {
|   "foo": "bar"
| }
- exit

Outside the template, you should rather not to call render or display method and just call raw PHP:

header('Status: 404 Not Found');
echo json_encode([
  'foo' => 'bar',
]);
exit;
Freest10 commented 6 years ago

Thank you