@define directive
To add properties to the context dynamically. Would be very useful...
This has been discussed a few times but there have been a few concerns that didn't sit well.
Are the @defines file scoped?
If not, then the concern is that the definition only occurs when the file including it is parsed and then the file order becomes more sensitive.
If we try to get around that then we need to preparse all the define directives in all the files before preprocessing the files.
What's the use case?
What's the use case?
@jsoverson I'm not sure if this is what you're asking for, but …
Using your Grunt Preprocess task, I'd like to pass vars from parent template to child/included template so I can manipulate the child/included template into doing things I need … For example, Let's say I have a header.text being included into index.html and sub.html. For sub.html I'd like the header.txt to behave differently; if I could pass vars to the child, then I could use conditionals to manipulate the template and/or include (or not include) other sub-sub template includes.
Not sure if that's a prime example … Just would be nice to have the ability to pass vars to includes so I can customize what the included files get to do on a per-template/include basis.
In terms of scopes, here's how grunt-include-replace does it:
@@include('bar.txt', {"test": "First"})
...
@@include('foo.txt', {"test": "Second"})
I have not used the above task, as I prefer Preprocess, but I would expect that the vars are only available to bar.txt and foo.txt respectively.
For comparison's sake, here's how we might use @define (based on your example given here):
<!-- @define test "First" -->
<!-- @include bar.txt -->
...
<!-- @define test "Second" -->
<!-- @include foo.txt -->
Questions:
- Would the second
testoverride the first? - How to define multiple vars? Could this be done in one
@definestatement? - Could variables be defined inline with the
@include? - How would you handle the included templates if they also set
@definestatements?
There's a part of me that wonders if you could hook into some sort of pre-existing template language like Underscore templates, Liquid, Handlebars, Mustache or something similar? Sorry if that's a dumb thought.
https://github.com/jsoverson/preprocess/pull/85