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

Choose a dotnet HTML templating library (other than DotLiquid?) #1

Closed
srid opened this issue Mar 27, 2021 · 4 comments · Fixed by #2
Closed

Choose a dotnet HTML templating library (other than DotLiquid?) #1

srid opened this issue Mar 27, 2021 · 4 comments · Fixed by #2
Assignees
Labels
decision Reflect, study, appraise and make a decision.

Comments

@srid
Copy link
Owner

srid commented Mar 27, 2021

DotLiquid (current choice) doesn't work well with arbitrary JSON input, and seems to require fiddling with advanced non-F# language features like ExpandoObject.

dotliquid/dotliquid#299 (comment)

decision matrix

virtual fs layouts JSON input
DotLiquid 🆗 🆗 ⚠️ #1 (comment)
Scriban ❔ Differently scriban/scriban#52 (comment)
fluid 🆗 🆗 sebastienros/fluid#291 🆗 sebastienros/fluid#290

legend:

  • virtual fs: continue supporting virtual filesystem of templates
  • layouts: layout extend, or includes
  • JSON input: allow passing arbitrary JSON to templates without having to define F# types
@srid srid self-assigned this Mar 27, 2021
@srid
Copy link
Owner Author

srid commented Mar 27, 2021

fluid's author comments about DotLiquid here,

Initially I tried to use dotLiquid but was faced with performance issues as it is using regular expressions to parse the templates.

@srid srid changed the title Find a DotLiquid alternative Choose a dotnet HTML templating library Mar 28, 2021
@srid
Copy link
Owner Author

srid commented Mar 28, 2021

JSON input is technically possible with DotLiquid, but it takes a lot of code: dotliquid/dotliquid#223 (comment) and dotliquid/dotliquid#299 (comment) - but it doesn't work reliably dotliquid/dotliquid#417

@srid srid changed the title Choose a dotnet HTML templating library Choose a dotnet HTML templating library (other than DotLiquid?) Mar 28, 2021
@srid
Copy link
Owner Author

srid commented Mar 29, 2021

I should try sebastienros/fluid#292 on Monday.

@srid
Copy link
Owner Author

srid commented Mar 30, 2021

FTR fluid requires the following to enable Json support, but it doesn't work in new master, and might need fixing:

        let enableJson(opts: TemplateOptions) =
            opts.MemberAccessStrategy.Register<JObject, JToken>(
                System.Func<JObject, string, JToken>(fun src name -> src.GetValue(name))
            )
            opts.ValueConverters.Add(fun x -> 
                match x with 
                | :? JObject as o ->
                    x
                | _ -> null)
            opts.ValueConverters.Add(fun x -> 
                match x with 
                | :? JValue as v ->
                    v.Value
                | _ -> null)

The JSON criteria has become much less important right now (because type-safety is a good thing in template variables) though, so I'll go ahead without working JSON support. The switch to fluid is good anyway due to performance benefits and active development.

@srid srid closed this as completed in #2 Mar 30, 2021
@srid srid added the decision Reflect, study, appraise and make a decision. label Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision Reflect, study, appraise and make a decision.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant