How to use Handlebars.Net to templatize a html template if it has 2 grids/tables? #549
-
Lets say I have a html template like this {{#each countries}} {{#each names}} and in c# I will haev 2 datasets - countries & names. What should be the syntax to fill both the grids/loops ? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
var result = template(new { |
Beta Was this translation helpful? Give feedback.
-
I think what you have mentioned cannot be used in C#. var LoadedTemplate = Handlebars.Compile(html); //countries & Names are 2 lists with the data populated in it |
Beta Was this translation helpful? Give feedback.
-
What you are trying would never work. Handlebars expects you to pass a single model object, and it expects the names in the template to map to properties on the model. In your case even if it did support multiple models, they aren’t named, so how would it know the first one is “countries” and the second one is “names”? As it is, the code example I shared above does indeed work in c# (I fixed a small typo). |
Beta Was this translation helpful? Give feedback.
-
Thanks @rexm for your explanation, can you help me understand how would the compiler understand wat object is When i try to use , I keep these compile time issues. If I seperately use different variable names , e.g. countryData,nameData - lists in C# , then wat will be countries & names? My understanding was that the same list name needs to be provided in the html template. It could be that I am missing something. Thanks for your assistance though!! |
Beta Was this translation helpful? Give feedback.
-
Sorry it should be = not : I updated it |
Beta Was this translation helpful? Give feedback.
var result = template(new {
countries = countryData,
names = nameData
});