alanshaw / grunt-include-replace

Grunt task to include files and replace variables. Allows for parameterised includes.
MIT License
200 stars 45 forks source link

conditional expression support #44

Closed michalliu closed 10 years ago

michalliu commented 10 years ago

I want a feature which supports conditional include some tpl, what should i do?

alanshaw commented 10 years ago

There's a few things you could do:

  1. Submit a pull request
  2. Use something different (perhaps https://github.com/assemble/assemble)
  3. Use a variable in the include statement:
@@include('/path/to/include/@@filename')

Replacements are processed before includes so this is possible. In your grunt config you could specify filename as a global variable and set it depending on your condition:

includereplace: {
  dist: {
    options: {
      globals: {
        filename: condition ? "consequence.html" : "alternative.html"
      }
    },
    src: '*.html',
    dest: 'dist/'
  }
}
michalliu commented 10 years ago

Thank you

XhmikosR commented 9 years ago

I wish this was supported :/

Because there are valid cases one won't need a separate include but just a different code block.