-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Introduce HttpRequest & HttpContext Fluid values #16979
Conversation
|
||
return name switch | ||
{ | ||
nameof(HttpContext.Items) => new ObjectValue(new HttpContextItemsWrapper(httpContext.Items)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add Request
, User
.. etc and deprecate the Request
object in a major release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this one @sebastienros?
src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Values/HttpRequestValue.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.DisplayManagement.Liquid/Values/HttpContextValue.cs
Outdated
Show resolved
Hide resolved
|
||
public override ValueTask<FluidValue> GetValueAsync(string name, TemplateContext context) | ||
{ | ||
var httpContext = _context ?? GetHttpContext(context).ToObjectValue() as HttpContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't cache the _context, it's specific to each request. Get a new value of the context every time this method is called. And don't wrap it in an ObjectValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to cache the HttpContext in case the fluid value is used multiple times (not common I'd say, and for what gain). You could use the TemplateContext
object which has a dictionary. And use a private constant to put it there. But again might be more work that benefits so I wouldn't advise that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't cache the _context, it's specific to each request. Get a new value of the context every time this method is called. And don't wrap it in an ObjectValue
The question again, how ToXXXValue() will be evaluated or should we ignore it for this particular object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it. Now I understand your question. And now you have your answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we have to decide what to render when we do {{ Request }}
. Here it's returning "Request"
, but we could decide to return the url (even if it's more costly) or something that is valuable. I am fine if you think ""
is actually better in that case, or "(Request)"
if that helps users understand that it's an object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with your changes, I was struggling to display something useful if we render {{ Request }}
but what you did is much simpler and doesn't require construction injection
Last two Liquid accessor