Coder Social home page Coder Social logo

Comments (2)

arnisjuraga avatar arnisjuraga commented on September 15, 2024 1

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:
{{ lipsum(5) }}

from gulp-twig.

olets avatar olets commented on September 15, 2024

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.

from gulp-twig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.