Replies: 11 comments
-
Well, I no longer think this is a bug but rather my lack of understanding.... it wasn't this:
or this:
but this works:
I don't know where the "Node" part comes from. It sort of reminds me of when accessing a field on the dynamic Content property and you have to have the content type name first. I do have a NodePart but it is on a ContentType called Article. The docs say "...if the content item has a Title part, we can access it like this:"
where the part name comes directly after "Content" with nothing in between... so I'd expect to just be able to have "NodePart" come right after "Content" and have it work. I found some examples in the source (e.g. LiquidPartHandler) where "ContentItem" is put into the Fluid context manually and I tried putting my content item's Content, ContentItem, and NodePart directly into context and still no luck. Any ideas of what that Node is and why it is needed? |
Beta Was this translation helpful? Give feedback.
-
Reading up more from https://deanebarker.net/tech/fluid/value-convertors/ and seeing related code in OrchardCore.Liquid's Startup class e.g. under comment "// Convert JToken to FluidValue." I see line I did notice I can also just stick stuff into the Fluid context and then get it back out but seems kind of weird to have to do that when "Content" seems to already be there, though I'm trying in another case to get a date/time value and it seems I may have to put it into context as a fluid value using DateTimeValue.Create()... if I want to be able to use things like |
Beta Was this translation helpful? Give feedback.
-
Ok, so it seems the that you can use templates with things like Content.NodePart.Text if you have this setup code in place:
This is directly from OrchardCore.Liquid.Startup's ConfigureServices method. I tried adding a reference to OrchardCore.Liquid and putting it as a dependency in my module's manifest but it didn't work. I'm guessing I've done something else wrong there but, convinced this was the code I needed to "teach" Fluid how to access stuff on the .Content property of my content item, I copied and pasted the above into my app's initialization code and voila, all was good. It seems to be giving member access strategies to read the dictionary style values when a property is requested (e.g. you requested "name?" well you can get that at source[name]). And the value converters dealing with the mystery "Node" by saying "when you put a JsonDynamicValue in a Fluid scope, don't look on that object itself but rather look at properties of the its "Node" property. I'd still like to know why it doesn't work when I just add the package ref and manifest dependency to OrchardCore.Liquid.Startup. |
Beta Was this translation helpful? Give feedback.
-
Did you enable the feature also? Does this code get hit (breakpoint?). |
Beta Was this translation helpful? Give feedback.
-
Thanks, yes, I referenced the nuget package, added it as a dependency in my manifest, and enabled the feature. I'm not sure if the code is being hit since I'm referencing the nuget package I don't know how to debug or put breakpoints in OrchardCore code referenced that way... Maybe I can download the OrchardCore source and try to reference the liquid project that way? Or, is there a better way to be able put a break point in referenced a OrchardCore package's code? |
Beta Was this translation helpful? Give feedback.
-
Ok, so I figured out how to get the symbols loaded and when I run my app, the ConfigureServices method of OrchardCore.Liquid's Startup class runs. I breakpoint on I'm not sure if it matters but I'm trying to do template parsing/rendering in code in a class called from a controller method. It isn't in the context of anything Orchard-specific like rendering a part. The above code seems like it is just setting up Fluid so not sure why it would matter but thought I'd mention it just in case. |
Beta Was this translation helpful? Give feedback.
-
ACTUALLY, it didn't hit those breakpoints under the branches of |
Beta Was this translation helpful? Give feedback.
-
Btw, if anyone stumbles across this and is wondering how I got debugging working, I've documented in #17572. |
Beta Was this translation helpful? Give feedback.
-
I guess one difference I can see is that the code in OrchardCore.Liquid (which doesn't seem to get used in my case) is doing |
Beta Was this translation helpful? Give feedback.
-
Based on the above revelation, I tried to get a hold of and use the options that the OrchardCore.Liquid module is setting up. So, in my class that does templating, I took a dependency on I'm going to try to figure out why it is crashing but is this the right general approach that we need to take a dependency on and use those options? I mean, it's doing a lot of stuff I probably don't need in my case like adding liquid filters I don't need for my usage... so maybe I'm better off just removing the reference to OrchardCore.Liquid, put back a direct reference to Fluid, and either keep using the the default options or create my own custom options object in the code where I need it. |
Beta Was this translation helpful? Give feedback.
-
Yeah, so just creating my own options object with the code from liquid also works:
Still not sure why using the |
Beta Was this translation helpful? Give feedback.
-
I'm trying to use the amazing Fluid functionality as part of my Orchard Core app. For testing purposes, when my app starts, I allow unsafe access just to ensure I have no security issues while I'm just trying to get template rendering working.
TemplateOptions.Default.MemberAccessStrategy = new UnsafeMemberAccessStrategy();
I create a new content item and store it in a variable "contentItem" and execute the following:
I can use all kinds values for the template text, such as:
It let's me get the year, month, or day the content item was published as well as its author. Excellent! At this point, I thought I was golden and could access anything under Content per the docs at https://docs.orchardcore.net/en/main/reference/modules/Liquid/#content-property For example, I have a "NodePart" with a "Text" property attached to contentItem so thought I could access that Text property via the "Content" object like this:
I also tried this out of curiosity:
but both end up wtih result = ""
The "Content" object itself returns something...
results in result = "System.Text.Json.Dynamic.JsonDynamicObject"
Interestingly, if I pause execution and use intellisense to look at the value, contentItem's Content property has a "Node" item under it with a Text property with the expected value I'm trying to get. And, if I just use:
template = fluidParser.Parse(@"{{ DisplayText }}");
I get the value I expect as that content item's "NodePart" has a handler that sets the content item's display text to the value of NodePart.Text.
Shouldn't I be able to use the above {{ Content.Node.Text }} template text to get NodePart.Text? It feels like I'm doing exactly what the docs say but it isn't working so it seems like a bug but maybe I'm just missing something...
Orchard Core version
2.1.6
Beta Was this translation helpful? Give feedback.
All reactions