Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //helpers.js
- module.exports = {
- truncate: (str, len) => {
- //code
- return str;
- },
- stripTags: input => input.replace(/<(?:.|n)*?>/gm, ''),
- formatDate: (date, format) => moment(date).format(format),
- select: function (selected, options) {
- return options.fn(this).replace(new RegExp(` value="${selected}"`), '$&selected="selected"').replace(new RegExp(`>${selected}</option>`), 'selected="selected"$&');
- },
- };
- //sets application locals so I can call these functions from a pug template
- app.locals = {
- truncate,
- stripTags,
- formatDate,
- select,
- };
- #{formatDate(story.date, 'MMMM Do YYYY')}
- select(name='status' id='status')
- #{select(story.status)}
- option(value='Public' selected) Public
- option(value='Private') Private
- option(value='Unpublished') Unpublished
- label(for='status') Status
- Cannot read property 'fn' of undefined
- <select name ='status' id='status'>
- {{#select story.status}}
- <option value='Public' selected> Public </option
- <option value='Private'> Private </option
- <option value='Unpublished'> Unpublished </option>
- {{#/select}}
- Warning
- Filters are rendered at compile time. This makes them fast, but it also means that they cannot support dynamic content or options.
- By default, compilation in the browser does not have access to JSTransformer-based filters, unless the JSTransformer modules are explicitly packed and made available through a CommonJS platform (such as Browserify or Webpack). In fact, the page you are reading right now uses Browserify to make the filters available in the browser.
- Templates pre-compiled on the server do not have this limitation.
Add Comment
Please, Sign In to add comment