Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot render nested anonymous objects returned from custom filter #685

Closed
arthurmmedeiros opened this issue Jul 24, 2024 · 1 comment
Closed

Comments

@arthurmmedeiros
Copy link

Hello there,

First of all I would like to thank for all the work that has been done in this library. I've been using it for a while, and it has been really useful in some of my projects.

Problem:
I am currently facing a problem with trying to write custom filter. I wanted to implement a custom filter that performs a group by and returns a list of grouped objects. I got it sort of working, the problem is that I cannot get it to access the nested objects inside the grouped lists. I can for instance access they key value of the objects, but the list of items seems to be ignored

To illustrate the problem, I have a template that looks like this
"<h1>Hello</h1><div> {% assign events_by_type = events | group_by: \"eventTypeId\" %} {% for type_group in events_by_type %} <div> {{type_group.key}} {% for item in type_group.items %} {{ item.name }} {{item}} {% endfor %} </div> {% endfor %} </div>"

and I am using a json object that looks like this:
"{\"events\":[{\"eventTypeId\":1234,\"type\":{\"id\":1234,\"name\":\"type 1234\"}}, {\"eventTypeId\": 1111, \"type\":{\"id\":1111,\"name\":\"type 1111\"} }]}"

This is the result I get
<h1>Hello</h1><div> <div> 1234 </div> <div> 1111 </div> </div>

This is what I was expecting
<h1>Hello</h1><div> <div> 1234 type 1234 </div> <div> 1111 type 1111 </div> </div>
anonymous objects
I have a json object containing all the data I want to render. The catch with this json object is that I cannot register my classes as instructed here. I want it to be generic as possible so I can work with any json object.

For this to happen I thought all I needed to do was to use UnsafeMemberAccessStrategy, but it does not seem to be the case.

Here is a simple repro https://dotnetfiddle.net/r0hkwE

I want to be able to do group by using metadata and by simple properties as well, hence why I do ToStringValue().Split(".").

I don't believe this is an issue with the custom filter itself since I can access the key values inside the list of objects. I cannot access the list of items inside the objects though.

I'm not sure if this could be a bug or if it's me.

@arthurmmedeiros
Copy link
Author

I realised my code was all wrong. Adde this PR with the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant