pug-php / pug

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

how to Including Filtered #122

Closed tienne closed 7 years ago

tienne commented 7 years ago

i want pugs includeing filter include:markdown /readme.md

https://pugjs.org/language/includes.html#including-filtered-text

but this compile

/readme.md how to use Including Filtered
kylekatarnls commented 7 years ago

Please see the README: https://github.com/pug-php/pug#supports-for-custom-filters

And markdown is already available as a composer package: https://packagist.org/packages/pug-php/pug-filter-markdown

List of trusted available filters here: http://pug-filters.selfbuild.fr/

tienne commented 7 years ago

@kylekatarnls i see this article but my case is here

include:escaped /readme.md

but compile result

<include:escaped>/readme.md</include:escaped>

Even if it is not a custom-filters, it will compile like that

kylekatarnls commented 7 years ago

This feature is not yet released nor in pugjs neither in our port, but it will be on the next (see the project if interested https://github.com/phug-php).

Until we do this I propose you the following solution:

Install pug and the markdown filter in your app. composer require pug-php/pug pug-php/pug-filter-markdown

Then you can use the same markdown library in a custom keyword include-markdown:

<?php

use Pug\Pug;
use cebe\markdown\Markdown;

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

$pug = new Pug(array(
    'basedir' => __DIR__,
));

$pug->addKeyword('include-markdown', function ($args) use ($pug) {
    $markdown = new Markdown();

    return $markdown->parse(file_get_contents($pug->getOption('basedir').$args));
});

echo $pug->render('
include-markdown /readme.md
');

Just set 'basedir' => __DIR__, with the directory that contains readme.md.

kylekatarnls commented 7 years ago

Hope this solve your problem, if not fell free to re-open this issue with failure details.

kylekatarnls commented 6 years ago

Hi, this syntax is now supported with the version 3.0.0, hope you will envoy this new version.

tienne commented 6 years ago

oh sorry, i see now this comment thank you!