Accessing object property using indexer notation
See original GitHub issueBased on the docs I was under the impression I can access a property of an object using either the simple dot-notation or the indexer-notation, e.g. if I have an object foo
with a property name
, I thought both of these are legal:
{{ foo.name }}
{{ foo["name"] }}
But a sample of my code that uses the indexer notation fails with this exception:
Unhandled Exception: Scriban.Syntax.ScriptRuntimeException: Expecting a list. Invalid value `Foo.Model.Attribute/Attribute` for the target `att` for the indexer: att[key]
Where att
is a global variable of the type Foo.Model.Attribute
– a native .NET type.
Do I misunderstand the usage?
The reason I was trying to resort to the index-notation is that the Attribute
type has a property named Null
which surfaces as null
in the scriban template and seemingly causes a conflict with the reserved keyword of the same name. For example, both of these are failing:
{{ if att.null }}Not Required{{ end }}
{{ if att["null"] }}Not Required{{ end }}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Property accessors - JavaScript - MDN Web Docs - Mozilla
Property accessors provide access to an object's properties by using the dot notation or the bracket notation.
Read more >How to access object using index notation - javascript
You can access on the inner block like this : cond[i]['Created ->OFP']. Example with loop : var cond = [{ "locality": "Dwarka", ...
Read more >Dot Notation vs Bracket Notation for Object Properties
There are multiple ways to access object properties in JavaScript. But two common ones are dot notation and bracket notation.
Read more >How to Access Object Properties in JavaScript in Three Ways
You use the dot notation to access the property you want. After that, you use square brackets and index to get the item...
Read more >How to Access Object Properties Dynamically Using Bracket ...
Index types tell the compiler that the given property or variable is a key representing a publicly accessible property name of a given...
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 FreeTop 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
Top GitHub Comments
Should be fixed by commit 548998c that will be part of
2.0.1+
I don’t remember 😉 (currently don’t have time to look into the code)