Allow `.length` in addition to `.Count` on arrays
See original GitHub issueIf the context data has a property called myArray
of type Array
, this expressions renders fine using the javascript version of Handlebars:
{{myArray.length}}
However, when I compile/render with Handlebars.Net, I have to change the expression to {{myArray.Count}}
to make it work. I get why that is, but it would be nice if our hbs templates would work in the Handlebars-JS as well, since we use JS-based tools for previewing etc.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Can I limit the length of an array in JavaScript?
Therefore, if you want to limit an array to some MAX_SIZE (modifying the existing array instead of creating a new instance) an easy...
Read more >Program to find sum of elements in a given array
The given code in Python is using the reduce() function from the functools module to calculate the sum of elements in the given...
Read more >JS Sum of an Array – How to Add the Numbers in a ...
In this article, you will learn how to calculate the sum of all the numbers in a given array using a few different...
Read more >Array: length - JavaScript - MDN Web Docs
When length is set to a bigger value than the current length, the array is extended by adding empty slots, not actual undefined...
Read more >How do get the array length? - Programming Questions
I don't see any examples of how to check for an arrays length. In JavaScript you use a method, len=array.length;.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure, but then we would have to add the same helper both in C# and javascript.
I can understand that it would feel a bit weird for the compiler to start looking for the string “.length”.
At the same time though… since Handlebars was originally written in Javascript, that sortof becomes the de-facto standard. So I think it would be a good ambition for this project to be able to render anything that can be considered a valid hbs template.
@vandre If you are only interested in Empty, you can also take a look at: https://github.com/Handlebars-Net/Handlebars.Net.Helpers
See https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers/Helpers/EnumerableHelpers.cs#L56