Comments (9)
Hi @russellr86, thank you for your feedback. Currently is only possible to hand in arrays into _foreach
-tags. Also the notation differs slightly from your code:
<!--(bake includes/li.html _foreach="name:[mike, drew, steve]")-->
But it is an idea to move the array-parsing from the _foreach
handler to a common behavior so we could apply it to inline-assignments in general.
from grunt-bake.
Thanks for the reply, David. Yeah I was easily able to get it working in a _foreach, however this restricts me from being able to keep my templates and components separate and flexible. In my templates, I simply want to reference the components I want to render. And I want to do this throughout an entire application without having to rely on JSON files for passing simple configuration values.
I think it would be a very nice enhancement as you can already pass string attributes to override json.
from grunt-bake.
Yes, I see the benefits of this. As it won't limit existing usage, I am sure @MathiasPaumgarten have nothing against changing / extending the behavior of bake. If you want you can create a PR if changes are urgent. Otherwise I will add it to my list. I will probably find time within the next 7 days to make the change.
from grunt-bake.
Thanks David, nothing urgent. By the way this tool has been a life saver so far, thanks so much.
from grunt-bake.
Interesting. Do I understand this correctly, that you want to pass the array to the partial as it is, and NOT loop over the array, correct?
We would have to workshop the syntax a bit. Because the way you wrote, we would essentially just pass the string ['http://www.google.com', 'http://www.github.com', '#anchor-2']
which is perfectly legal.
So in other words, there should be some sort of logic that recognizes if a variable passed is a more than just an attribute?
How would you like the value to be handled in the the partial? Something along the those lines:
<a href="{{ links[ 0 ] }}">Linky Link</a>
from grunt-bake.
Funny, I was just thinking about this enhancement and making some tests. One already existing solution is to make use of transforms
in the sub-template to break things down:
usage.html
<!--(bake component.html links="['http://www.google.com', 'http://www.github.com', '#anchor-2']")-->
component.html
<ul>
<!--(bake-start _foreach="link:links | evaluate")-->
<li>{{link}}</li>
<!--(bake-end)-->
</ul>
options in Gruntfile.js
transforms: {
evaluate: function( string ) {
return string.slice(1, -1).split("'").join("").split(","); // just quick hack
}
}
This solution works without any changes in bake 👍 You can try it out @russellr86
However, I like the idea to make the array parsing of _foreach
available to var-definitions in general.
from grunt-bake.
@MathiasPaumgarten, yeah pretty much, it would just allow you to pass an array, and then do something like a _foreach
in the view to loop through the items in the array passed. Or referencing with the index would be nice too if that is an option.
@david-zacharias I'll try that out, thanks
from grunt-bake.
Yeah, not opposed to it. However we have to figure out how the syntax differs from sending a string of an array. or an object. Probably drop the "
around it. That might open another can of worms though.
Anybody dare to form a PR? 😈
from grunt-bake.
You are right, that change affects more parts of the code as I expected. I have a running version, that keeps all tests green and adds the new features. But the code is not as clean as I want it to be. So I have to think about it for some more time. As I have not much time for code right know it will take some time. To answer your question, I can take care of the PR, but it will take time.
from grunt-bake.
Related Issues (20)
- Version for gulp HOT 1
- When in '_section', use properties outside this '_section' HOT 11
- Evaluate content inside of _section HOT 1
- Add variable for linking to originating file when using _bake-attribute HOT 2
- Integration of default transforms HOT 1
- Can't access properties in _section HOT 1
- bake-escape feature request HOT 20
- JSON file or CSV convert to multiple HTML files HOT 9
- Simple bake test HOT 1
- foreach loop to build multiple files per object HOT 1
- Unset variables are rendered as "undefined" HOT 3
- Placeholder Default HOT 5
- Assign/use variable in same file HOT 1
- Builtin placeholders HOT 2
- How to convert a folder with bake ? HOT 2
- Generate Bake with grunt.config.get HOT 2
- Bake one HTML file / JSON section in one go HOT 5
- Iteration over objects in _foreach HOT 6
- Can I read from package.json? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-bake.