Set List Placeholder
Closed this issue · 10 comments
For example: Listlist=new List() {"123", "333"}
Use: field: {{list}}
The result is: value: 123,333. How to: field: ["123", "333"]
You can use the json
filter like this: field: {{ list | json }}
. If you have configured an encoder that would mess up with the output (HtmlEncoder for instance) you can also do {{ list | json | raw }}
Thank you. This is really OK, but I thought of escaping, for example: field: ["123", "333"]
is changed to: field: [\"123\", \"333\"]
I can't reproduce what you are describing. Here is my attempt (https://dotnetfiddle.net/q5EvIk):
using System;
using System.Collections.Generic;
using System.Text.Encodings.Web;
using Fluid;
public class Program
{
public static void Main()
{
var parser = new FluidParser();
var t = parser.Parse("{{ list | json | raw }}");
var context = new TemplateContext();
context.SetValue("list", new List<string>() {"123", "333"});
Console.WriteLine(t.Render(context));
}
}
Can you provide some code sample showing how you are getting this result?
You have misunderstood me. The result is no problem, but I want to add escape.
Correct: field: ["123", "333"]
, I want to: field: [ \"123 \", \"333 \"]
I can only think about this if you are trying to generate a C# string containing some json. Then in this case you could just do {{ list | json | raw | replace: '"', '\\"' }}
but there might be other replacements to do in case some json string are already escaped.
Obviously, this syntax is invalid: | replace: '"', '\\"'