simon-dt / gulp-twig

Twig plugin for gulp.js, The streaming build system. Looking for maintainer or collaborators. See wiki
https://github.com/zimmen/gulp-twig/wiki/Looking-for-maintainer-or-collaborator(s)
MIT License
62 stars 33 forks source link

Is it possible to generate random dummy text, e.g. using lorem? #64

Closed arnisjuraga closed 4 years ago

arnisjuraga commented 4 years ago

Twig Symphony has lipsum tag: https://twig.symfony.com/doc/3.x/advanced.html which allows to generate random Lorem Ipsum texsts.

{% lipsum 40 %}
{% lipsum(40) %}
{{ lipsum 40 }}
{{ lipsum(40) }}

How I can do that in gulp-twig?

And even more, to be able to generate this "random", e.g. - if I have to generate 10 blocks, each block would have different "lorem text", as it's in Emmet shortcode - it generates different Lorem every time.

Something like

{% lipsum(40,true) %}
olets commented 4 years ago

The lipsum examples in that link are just examples of extensions you could write and add. They aren't actually available in Twig (FYI the thing at symfony.com is commonly called "Twig" or sometimes "TwigPHP". Symfony is the "maker" of Twig. Also, potentially confusingly, it's the name of other products they make.) You can verify this by trying the pseudocode in a fiddle

With gulp-twig you can add new tags (using the "extend" option), functions (using the "functions" option), and filters (with the "functions" option). For more info see the README's Options section and the Twig.js wiki's "Extending Twig" documentation (gulp-twig uses Twig.js under the hood). There are some more examples at https://symfony.com/doc/current/templating/twig_extension.html

If you do make a lorem ipsum extension please share a link! That'd be neat.

arnisjuraga commented 4 years ago

Great! Thanks for leading in right direction. I have done this.

// pipe to twig with options thanks to #8fe69960f0a62cf030e7d36372927fa83d002fba ... .pipe(twig({ functions: [{ name: "lipsum", func: function (args = 1) { return lorem.generateSentences(args);; } }] } ))


- in `index.twig` as an example:

```twig
{{ lipsum(5) }}