Apply TemplatePagesFeature only to a specific path

I am axious to explore more of the new Templates features, and I would like to have the TemplatePagesFeature only apply to a specific url route, can’t seem to get the settings configured right.

For example, if route starts with /templates/ look for files in subfolder “templates”. This isn’t quite enough, seems the FS has to be added to AppHost and can’t be directly on the Template feature.

Plugins.Add(new TemplatePagesFeature { VirtualFiles = new FileSystemVirtualFiles("~/templates".MapServerPath()) });

Alternatively, if I create my own template context to be used from a custom service/route, there is a lot of functionality to replicate from what I see here

I also can’t seem to get a template file to reload. Refresh will update the data, but the raw template files aren’t reloaded. How?


Use a new TemplateContext in a custom Route + Service impl, you don’t need to reimplement the entire TemplatePagesFeature. But you’ll need to return a PageResult with the pages you want to render.

There are a lot of examples in TemplatePages repo which returns a custom PageResult.

Using a new TemplateContext won’t cache the compiled page, also if using TemplatePagesFeature in DebugMode will check for modified pages and reload them.

Are you running into any issues by just registering TemplatePagesFeature that you want it limited to a specific sub directory? Note you can easily ignore .html pages or configure it to use a different.htm extension with:

Plugins.Add(new TemplatePagesFeature { 
    HtmlExtension = "htm" 

Mainly because I am not looking to host it as part of the webapp exactly, and have different format templates in different folders (xml, html, md…) for various scenarios. I guess in that case it will prob be best to use multiple Template Contexts and invoked from custom service routes.

I think I found my problem with setting the FilesSystemProvider directly on the template context … I forgot to call Init!