Closed arnisjuraga closed 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.
Great! Thanks for leading in right direction. I have done this.
install lorem-ipsum
npm i lorem-ipsum --save-dev
define variables in gulpfile.js
var twig = require('gulp-twig');
var LoremIpsum = require( "lorem-ipsum").LoremIpsum;
// Lorem Ipsum
const lorem = new LoremIpsum({
sentencesPerParagraph: {
max: 8,
min: 4
},
wordsPerSentence: {
max: 16,
min: 4
}
});
// 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) }}
Twig Symphony has
lipsum
tag: https://twig.symfony.com/doc/3.x/advanced.html which allows to generate random Lorem Ipsum texsts.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