Multitenancy and different layout if available

I’m using #script in a multi tenant website. There’s a default _layout page, but for a specific tenant I want to create a custom layout page. So it should use the custom layout file if availabe else use the default.
Any best practice tips how to configure this scenario?


One more additional question around using the correct _layout file. Next to a tenant specific version there could also be a desktop/mobile/tablet specific layout page.

There’s no special support for tenants, but you can dynamically change which layout to render by returning a custom PageResult with the layout you want, e.g:

public class CustomerServices : Service
    public object Any(ViewCustomer request) =>
        new PageResult(Request.GetPage("examples/customer")) {
            Layout = "...",
            Model = TemplateQueryData.GetCustomer(request.Id)

You can also change which Layout to use by setting the “Template” IRequest.Items which you can do in a Request Filter, e.g:

req.Items[Keywords.Template] = "..."

This is what [ClientCanSwapTemplates] uses to allow views to be specified on the QueryString, e.g:

public class ClientCanSwapTemplatesAttribute : RequestFilterAttribute
    public override void Execute(IRequest req, IResponse res, object requestDto)
        req.Items[Keywords.View] = req.GetParam(Keywords.View);
        req.Items[Keywords.Template] = req.GetParam(Keywords.Template);