2

Closed

Cannot access to Model properties of non-integral types

description

I can understand StaticShape provides a statically-types proxy for accessing shape objects but what is the solution for other not supporting types in DotLiquid?

I cannot access to some properties of my Model. For example i cannot access property of Model even for Dictionary type but DotLiquid supports Dictionary or List internally.

Also we can use Drop, RegisterSafeType, ILiquidizable, etc for using complicated types but i cannot see extension point for using these types. I only access to properties of base types (int, string, ...).

Can you please help me to understand how i can use this view engine instead of razor?
Shapes in Orchard may have some complicated properties. It seems this module has more limitation over DotLiquid as i describe above.
My goal is sending JObject or dynamic as a property of Model for using in template.
I can do this by DotLiquid directly but cannot do by this module.

Please help.
Closed Jun 4, 2015 at 1:55 PM by Piedone

comments

Piedone wrote Dec 12, 2014 at 8:53 PM

Could you please give a complete example? I.e. what is the Model object you use (the complete class), what do you try to do in the template (with Liquid code) and what the unexpected output is.

Thank you.

mehranrezaei wrote Dec 13, 2014 at 12:49 AM

Thank you for your reply. Here is a simple example:
IShape shape = shapeHelper.Create("Test", Arguments.From(new
                {
                    Id = 1,
                    Dic = new Dictionary<string, string>() { { "key", "val" } },
                    Data = JObject.Parse("{ 'name': 'value' }").ToObject<dynamic>(),
                    Flag = true,
                    EditUrl = "edit url"
                }));
                
var content = _shapeDisplay.Display(shape);
And template is:
{{ Model.Id }}
{{ Model.Dic["key"] }}
{{ Model.Data["name"] }}
{{ Model.Flag }}
{{ Model.EditUrl }}
It is normal that i cannot access to Model.Data because JObject needs writing some special code to work but DotLiquid supports Dictionary by default.

I think this issue related to the logic of this[object key] in StaticShape class.

mehranrezaei wrote Dec 13, 2014 at 12:52 AM

Please be aware that i can get value for Id, Flag and EditUrl in above template.

Piedone wrote Dec 14, 2014 at 7:19 PM

Fixed in changeset bbbd27d1835d

Piedone wrote Dec 14, 2014 at 7:21 PM

Thanks for the details. Implemented that models with an indexer, like dictionaries will work.

This also allows you to use JObject: however note that using the indexer on the JObject actually returns a wrapper object, not the value. Thus you'd need to use {{ Model.Data["name"].Value }} for JObjects.

mehranrezaei wrote Dec 14, 2014 at 7:44 PM

Thanks a lot. I will test it again ASAP.