Comments (2)
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.
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)
- How to exclude files? HOT 4
- fails tests when using twigjs 1.10.4 HOT 2
- Support for Null-coalescing operator HOT 1
- Add me as a contributor HOT 10
- ‘set’ variable causes a bug HOT 7
- json_encode with constant
- bringing releases up to date HOT 8
- data variable reference bug HOT 2
- include TwigException HOT 7
- {{ dump() }} crash gulp HOT 2
- Does not return valid json
- Correct syntax when using with gulp-data? HOT 3
- How to use Base option properly with Extends, Block, Include and Import tags? HOT 1
- twig conditions error
- Actual example of gulp-data use
- Passing twig options
- Error compiling twig template
- How to use function "source"? HOT 1
- include .html with variables go wrong
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-twig.