preprocess icon indicating copy to clipboard operation
preprocess copied to clipboard

Include with a variable?

Open elado opened this issue 9 years ago • 8 comments

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.

elado avatar Jun 22 '15 19:06 elado

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.

BendingBender avatar Jun 22 '15 22:06 BendingBender

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

elado avatar Jun 22 '15 22:06 elado

Can I close this or is this a feature request?

BendingBender avatar Jun 22 '15 22:06 BendingBender

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

elado avatar Jun 22 '15 22:06 elado

We'll see what we can do :-)

BendingBender avatar Jun 22 '15 22:06 BendingBender

was tis ever implemented?

karneaud avatar Nov 25 '15 21:11 karneaud

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

dogancelik avatar Aug 17 '16 22:08 dogancelik

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.

TheShanMan avatar Oct 05 '20 19:10 TheShanMan