abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.77k stars 3.41k forks source link

[Bug] Text Templating: Model property names with more than one word aren't rendered #6188

Closed yekalkan closed 3 years ago

yekalkan commented 3 years ago

await _templateRenderer.RenderAsync(AbpIoEmailTemplates.ArticleNotifyNew, new { Title = article.Title })

Rendered as expected in template file with {{ model.title }}.

await _templateRenderer.RenderAsync(AbpIoEmailTemplates.ArticleNotifyNew, new { ArticleTitle = article.Title })

isn't rendered in template file with any "case" combination. What i've tried: {{ model.ArticleTitle }}, {{ model.articleTitle }},{{ model.articletitle }}.

You can reproduce this on Hello Demo.

colinin commented 3 years ago

I also met this situation, in TemplateRenderer.RenderAsync , all model attributes must be lowercase, For example:

await _templateRenderer.RenderAsync(AbpIoEmailTemplates.ArticleNotifyNew, new { articletitle = article.Title });

also must be the same in a .tpl: {{ model.articletitle }}

mehmetuken commented 3 years ago

Scriban default property and methods naming kebab-case. Using ArticleTitle atricle_title. It's not bug.

NOTICE By default, Properties and methods of .NET objects are automatically exposed with lowercase and _ names. It means that a property like MyMethodIsNice will be exposed as my_method_is_nice. This is the default convention, originally to match the behavior of liquid templates. If you want to change this behavior, you need to use a MemberRenamer delegate

gdeswardt commented 3 years ago

This is not a bug, but the documentation should be updated to as it states that camelCase is the default

https://github.com/abpframework/abp/blob/dev/docs/en/Text-Templating.md#pascalcase-vs-camelcase

PascalCase vs camelCase PascalCase property names (like UserName) is used as camelCase (like userName) in the templates.

and instead, it is using the snake case as the default member renamer as specified in scriban documentation

https://github.com/lunet-io/scriban/blob/master/doc/runtime.md#member-renamer