jsoverson / preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
Other
366 stars 80 forks source link

Include with a variable? #73

Open elado opened 9 years ago

elado commented 9 years ago

Is there an option to put a variable in an include?

  <!-- @if BLAH -->
    <!-- @include BLAH/file.html -->
  <!-- @endif -->

Tried also

<!-- @include $BLAH/file.html -->

But it doesn't replace the variable, so it doesn't find the file.

BendingBender commented 9 years ago

No, not at the moment. As a workaround, you could try to combine this with @foreach in the following manner:

<!-- @if BLAH -->
  <!-- @foreach $BLAH in ['somefile'] -->
    <!-- @include $BLAH/file.html -->
  <!-- @endfor -->
<!-- @endif -->

But I have no idea whether it will work or not.

elado commented 9 years ago

Thanks. I just used gulp-replace for now to replace specific variables before preprocess. Does the job.

BendingBender commented 9 years ago

Can I close this or is this a feature request?

elado commented 9 years ago

I think it'd be a good addition to preprocess, replacing $VAR or ${VAR} with the value before handing @include.

BendingBender commented 9 years ago

We'll see what we can do :-)

karneaud commented 8 years ago

was tis ever implemented?

dogancelik commented 8 years ago

Would be a good addition.

Preprocess context:

context: {
  test: 'hello-world'
}

File to preprocess:

// @include-static ${test}.js

console.log(1);

So that @include-static ${test}.js is @include-static hello-world.js

TheShanMan commented 4 years ago

No ability to use a variable with @include still? I was hoping to generate html files from a common template using this by passing the @include file in via context.