fvsch / kirby-twig

Twig templating support for Kirby CMS 2. For Kirby 3, use https://github.com/amteich/kirby-twig
MIT License
70 stars 8 forks source link

Mark Kirby helper functions as safe HTML output? #2

Closed fvsch closed 8 years ago

fvsch commented 8 years ago

From: https://gist.github.com/namaless/469b04b9cbb0356e03cb

$twig->addFunction(new Twig_SimpleFunction('css', function($css) {
    return css($css);
}, ['is_safe' => ['html']]));
nunocodex commented 8 years ago

This can output html code instead a filtered html :)

I love twig but for simple templates not really need, for a moment I never used twig for my projects, I used only in one where I have over 120 snippets and 20 templates.

fvsch commented 8 years ago

Yeah, the only thing I have doubts about is that if we mark those snippets as safe HTML:

So this creates a difference that is hard to reason about for template authors.

Another option would be to have two lists of helper functions:

  1. First list is marked as safe HTML: snippet, css, js
  2. Second list is for working with page content, so we don’t mark it as safe.

For the record there’s a plugin setting for disabling Twig’s autoescaping:

c::set('plugin.twig.autoescape', false);
nunocodex commented 8 years ago

I think is a bad way to disable autoescape, the best way (and bad as well) is add all kirby helpers to twig (example from my gist), in this way all kirby helpers working fine. For your example is simple {{ pate.text.markdown | raw }}

for my previous idea is translate with {{ page.text | markdown }} instead {{ markdown(page.text) }}

fvsch commented 8 years ago

Okay, so: