How to pass a list of ContentItem
to Liquid so it can be rendered?
#14085
-
I am trying to pass a list of Here is how I am processing a Liquid message private async Task<string> GetContentAsync(string message, IUser user, ContentItem contentItem, IDictionary<string, ContentItem> events)
{
var result = await _liquidTemplateManager.RenderHtmlContentAsync(message, _htmlEncoder, null,
new Dictionary<string, FluidValue>()
{
["User"] = new ObjectValue(user),
["ContentItem"] = new ObjectValue(contentItem),
["ContentEvents"] = new DictionaryValue(new ObjectDictionaryFluidIndexable<ContentItem>(events, _templateOptions)),
});
using var writer = new StringWriter();
result.WriteTo(writer, _htmlEncoder);
return writer.ToString();
} Then here is my Liquid syntax
The loop seems to work. But,
@jtkech any idea what am I missing here? I am guessing |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I don't know, I assume that you retrieve Maybe use And/or use Hmm, I don't think that a |
Beta Was this translation helpful? Give feedback.
-
Yes I am.
Tried both with no luck. But using the following finally worked!
Thank you for your feedback! |
Beta Was this translation helpful? Give feedback.
-
Yes because you were looping through a dictionary returning KeyValuePairs |
Beta Was this translation helpful? Give feedback.
I don't know, I assume that you retrieve
_templateOptions
throughIOptions<>
.Maybe use
IDictionary<string, object>
orIDictionary<string, FluidValue>
.And/or use
FluidValue.Create(ContentEvents, _templateOptions)
.Hmm, I don't think that a
MemberAccessStrategy
is needed for the dictionary itself.