Repository navigation
Description
As a celebration of Handlebars.Net's millionth installation, it seems like a good time for:
Handlebars.Net Version 2.0 🎉
This thread will be to discuss what goes into 2.0. Really appreciate everyone's involvement, even if it's just bringing your experience and input to the table.
Call for Input
So far, here's the changes being considered (in no particular order): As consensus develops in this thread, approved items will get a [x] to indicate they're officially part of the 2.0 roadmap. Please review, comment, and add your own:
- Make all the function names match handlebars.js (for example, changing
RegisterTemplatetoRegisterPartial) - Be able to return a value from a helper (and generally restructure the helper delegates to be more js-esque) (see Support for returning a complex object from a subexpression #264)
- Support more advanced helper construction (see Question: How to create a custom helper with access to @index #151)
- Add a
Compile<ExpectedModelType>()overload for performance optimization - Support for decorators (see Decorators implementation #137)
- Support the
as |alias|syntax for enumerators (see Sequence contains more than one element #301) - Refactor the compiler so it can provide line numbers of errors and syntax hints (see Add line number in handlebars exceptions #156, Please report betters errors (context) when having mistakes in the template #314)
- Remove the built-in filesystem based templating extension, but ensure we have a good extensibility model so it can still be added as an external plugin
- Support
noEscape(see Can't seem to handle German umlauts.... #276)
Special thanks
to @mcintyre321, @Magentaize, @dejx, @amaclean, @vzwick, @axelheer, @sandorfr, @leniency, @pmccloghrylaing, @mikeprince3, @StefH, @huysentruitw, @abraham-fox, @ondrejtomcik, @mohd-akram, @EBMike, @JvanderStad, @katavasha, @Andrew-Hanlon, @nblumhardt, @crra, @esskar, and the many others who've helped make this library useful to people all over the world in the last 5 years!
Activity
rexm commentedon Apr 27, 2019
Plan to address #292
rexm commentedon Apr 27, 2019
Plan to address #297
rexm commentedon May 26, 2019
Plan to address #301
johnknoop commentedon Jun 22, 2019
Suggestion for v2:
I'm not sure if this is even possible using the tools available, but here's my idea:
We only use Handlebars to render html e-mails, and I imagine that's what most people use this library for, since rendering website UI's using Handlebars in .NET seems like an unusual thing to do. And given the nature of e-mail clients, a common setup is to produce the e-mail body in this sequence:
imgelements in the html, and create CID-embedded attachments.Now, step 3 and 4 doesn't really have any dependency on the context data used in step 2. Therefore, it's a shame we can't do step 3 and 4 as part of the compilation, so it only has do be done once per template. Now I have no idea how the execution flow looks when it comes compiling a Handlebars template, but it would be nice if one were able to register hooks that get called by
Handlebars.Compile:And the return type of
Handlebars.Compilewould be:With this approach, the task of rendering an e-mail body would be so much quicker since all that has to be done is step 2 instead of steps 2, 3 and 4.
I don't know enough about the internals of how Handlebars templates get compiled. But if this seems reasonable and possible to do, then I'd be happy to help out implement it. But I don't want to add it to the checklist above before I know if this is even a sensible thing to do and if it's inline with the vision of this project.
rexm commentedon Jun 22, 2019
The main goal of this project is to have a .NET native implementation of the handlebars JS library. The handful of times we’ve bent and added features that aren’t in the original handlebars library, it’s ended up being a mistake. That being said, since .NET and JS are different platforms, it can make sense to diverge. It should make sense based on those differences and be universally useful - contrary to your perception, while generating emails is one popular use-case, it is also widely used as a website templating engine, a code generator (not something I’d recommend, but it gets used that way) and a lot of others. Compiler hooks could make sense, but we’d need to work on a model that is useful to everyone and doesn’t commit us to supporting contracts we end up regretting.
johnknoop commentedon Jun 22, 2019
Maybe compiler hooks could be part of the extensibility model you mention above. But I don't even know if html in -> html out would make sense as a contract for such hooks. You might work with other primitives than strings of html during the assembly process?
Also, everything I've written is based on the assumption that partials are sucked in during compilation, and not later on when the compiled template is rendered. Is this a correct assumption btw?
rexm commentedon Jun 22, 2019
When a template is compiled and a partial is referenced, that reference is replaced by a function to look up the partial by name and invoke it during execution. What are you thinking you could do with that?
johnknoop commentedon Jun 23, 2019
In the e-mail scenario, you typically wanna apply the CSS inlining after all partials have been pulled together into a single html document, because you might have styles coming from one partial and the elements from another. I just assumed this was how the compilation process looked, meaning the result of the compilation was a complete hbs document where all partials have been sucked, and the only thing happening during rendering was turning the remaining handlebars expressions into strings using the context data.
So given this, perhaps there's no real use for compilation hooks in my case.
rexm commentedon Jun 23, 2019
Have you considered inlining before template compilation? Even as part of the build...
johnknoop commentedon Jun 23, 2019
I have, The problem is that styles might reside in a partial for reusability, so it's only when a template has been assembled into a complete html file that I can safely apply the inlining.
rexm commentedon Jun 23, 2019
I suggest exploring some other structures to achieve the same result without introducing the same challenges.
17 remaining items
bags1976 commentedon Jun 12, 2020
The handlebars api has a method to parse the ast/tokens returned prior to invoking the compile.
https://github.com/handlebars-lang/handlebars.js/blob/master/docs/compiler-api.md
This would be very useful to allow a user to extract the tokens from a template and then be able to extract the variables required for a particular template. The feature of extracting the variables was requested long ago here in the native handlebars.js and ultimately is what I would love to see implemented as well.
handlebars-lang/handlebars.js#1207
Currently there is no way to have the compiler parse the template for tokens and simply return the results in the interface and they are internal classes / methods so there is no good way to extract this information now.
elkhawajah commentedon Sep 9, 2020
The v1.0 is not compatible with .net core 2.2 right ? what is the alternatives for a compatible version for a production app ? Seems v2.0 not officially released yet.
Thoughts please.
StefH commentedon Sep 9, 2020
The current Handlebars.net does support NETStandard 2.0 so it can be used by .net core 2.2
elkhawajah commentedon Sep 9, 2020
oformaniuk commentedon Oct 16, 2020
@johnknoop, starting from 2.0 this scenario would be achievable using low-level
IExpressionMiddlewareinterface. Interface allows transformations on Expression Tree before it is compiled. In order to get desired behaviour you'd need to implement customExpressionVisitorto walk the tree and perform steps 3 and 4.StefH commentedon Oct 16, 2020
Maybe already in place : make sure the library is signed.
StefH commentedon Nov 4, 2020
@zjklee
Maybe add a config option to "keep the replacement as-is if the value cannot be replaced"
Like:
Result should be:
https://stackoverflow.com/questions/64379082/handlebars-net-how-to-change-behavior-if-data-does-not-exist
oformaniuk commentedon Nov 4, 2020
@StefH , see /issues/373
StefH commentedon Nov 4, 2020
@zjklee This looks perfect!
Maybe you can answer that StackOverflow question? The credit is yours ;-)
sferencik commentedon Dec 2, 2020
@zjklee what's your ETA on this? We're keen to start using some of the new features; should we wait or build our own pre-release version?
oformaniuk commentedon Dec 2, 2020
@sferencik originally I was planning to address #97 before publishing a release version as it would introduce a dramatic breaking change to the public API. However it looks like I'd defer it to 3.0 release.
Regarding ETA: I'm planning to release one more pre-release version today/tomorrow after #391 is merged. This pre-release package would be the last one before I publish release version unless any critical bugs are found. I guess you can expect a release version by the end of the week.
sferencik commentedon Dec 6, 2020
That would be great, thanks! Is there something I can help with?
oformaniuk commentedon Dec 6, 2020
I'm trying to keep the list of issues up to date so in case you want to contribute I'd definitely be happy to accept PRs.
oformaniuk commentedon Dec 6, 2020
Release 2.0.0 is out.