Profiles
Create & Register
You might be aware, if you add same key (in one or different profiles), first added template would be used.
Temply allows you to define profiles as:
Profile Type
Profile might have parameterless constructor.
public class MyTemplyProfile : TemplyProfile
{
public override void Configure(TemplyProfileBuilder builder)
{
// ...
}
}
services.AddTemply(x => x.AddProfile<MyTemplyProfile>());
Profile Instance
public class MyTemplyProfile : TemplyProfile
{
private readonly IWebHostEnvironment _environment;
public MyTemplyProfile(IWebHostEnvironment environment)
{
_environment = environment;
}
public override void Configure(TemplyProfileBuilder builder)
{
// ...
}
}
services.AddTemply(x => x.AddProfile(new MyTemplyProfile(_environment)));
Profile Delegate
services.AddTemply(x => x.AddProfile(profile => /* .... */));
Builder
Profile builder allows you to configure your template. It has following methods:
Add - adds in memory resource
AddFile - adds file content as resource (when template key not specified, uses file name without extension as Template key)
AddYaml - adds YAML entries as resources
users:
hello: Hello {{ values.name }}
bye: Bye {{ values.name }}would be added as
users.hello
andusers.bye
template keysAddJson - adds JSON entries as resources
{
"users": {
"hello": "Hello {{ values.name }}",
"bye": "Bye {{ values.name }}"
}
}would be added as
users.hello
andusers.bye
template keysAddDir - adds directory files (not recursive) as templates
.html, .htm, .txt, .md
- files added usingAddFile
call
.yaml, .yml
- files added usingAddYaml
call
.json
- files added usingAddJson
callNote:
noCache
option would not affect newly added files (they would ignore)Add(Resource Loader) - adds built-in or custom implementation of resource loader