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

Fluid seems to work for ContentItem but not custom parts #17538

Open
fuzl-llc opened this issue Feb 28, 2025 · 0 comments
Open

Fluid seems to work for ContentItem but not custom parts #17538

fuzl-llc opened this issue Feb 28, 2025 · 0 comments
Labels

Comments

@fuzl-llc
Copy link
Contributor

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:

var fluidParser = new FluidParser();
var context = new TemplateContext(contentItem);
var template = fluidParser.Parse(THE_TEMPLATE_TEXT);
var result = await template.RenderAsync(context);

I can use all kinds values for the template text, such as:

template = fluidParser.Parse(@"{{ PublishedUtc | date: ""%Y"" }}");
template = fluidParser.Parse(@"{{ PublishedUtc | date: ""%m"" }}");
template = fluidParser.Parse(@"{{ PublishedUtc | date: ""%d"" }}");
template = fluidParser.Parse(@"{{ Author }}");

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:

template = fluidParser.Parse(@"{{ Content.Node.Text }}");

I also tried this out of curiosity:

template = fluidParser.Parse(@"{{ Content.NodePart.Text }}");

but both end up wtih result = ""

The "Content" object itself returns something...

template = fluidParser.Parse(@"{{ Content }}");

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

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

No branches or pull requests

1 participant