You are not logged in.
Pages: 1
On my MVC Web Application I have a folder structure similar to the example 30:
ROOT
|-views
|-.static
Now I need add a billing system on my application. I don't want to create a rigid system.
My idea is create a "template system", the user can be edit (and if he want add) 2 files for any bill type: un javascript file for "logical" (I use spidermonkey for it) and a html file for "model" to use with mustache.
I'd like create a folder on ROOT with these files, in alternative in fact the user should change "views" folder with the risk of doing damage:
ROOT
|-views
|-.static
|-templates
|-.static
So I should customize the VIEW path and VIEW filename for a specific command, for example when the user call "CreateInvoice" command the application should check invoice templete used by user on database and then use the specific VIEW from "templates" folder.
Is this is possible? How?
Offline
Class TMVCViewsMustache has virtual methods FindTemplates, GetTemplate and GetStaticFile.
So you can customize process of reading templates and static files.
For example, see Virtual methods for loading templates in MVC Web App.
Offline
Class TMVCViewsMustache has virtual methods FindTemplates, GetTemplate and GetStaticFile.
So you can customize process of reading templates and static files.For example, see Virtual methods for loading templates in MVC Web App.
If I understand your post, in this way I need "handle" ALL views and not only a part of them, right?
In my case I should handle (I think by filename) both "template" views and "basic" views, right?
Offline
With TMVCViewsMustache I can customize folder templates by template filename.
But I can customize filename view from command of the web application?
I have a command like "ShowInvoicePreview" to create an invoice preview, however the user can choose between more invoice template (I use mustache and "view style" saved on custom path) besides user can create more of them. So the "ShowInvoicePreview" should read from db the invoice template for current user and use the right view (saved on custom path).
By default mORMot use a view with the same name of command, is there a way to customize the view name from code?
Offline
If you need per-user template, you can do it in that way:
1. Define ShowInvoicePreview.html like
{{#Scope}}{{{Result}}}{{/Scope}}
2. In ShowInvoicePreview function call GetUserInvoicePreview.
3. Create GetUserInvoicePreview as in example:
type
TMyAppViews = class(TMVCViewsMustache);
function TMyApp.GetUserInvoicePreview(var Scope: Variant): RawUTF8;
var
LTemplate: RawUTF8;
LMustache: TSynMustache;
LContext: Variant;
begin
LTemplate := <Load from DB...>;
LContext := _ObjFast(['main', GetViewInfo(-1), 'Scope', Scope]);
// TSynMustache maintain internal template cache
LMustache := TSynMustache.Parse(LTemplate);
Result := LMustache.Render(LContext,
TMyViews(FViews).fViewPartials,
TMyViews(FViews).fViewHelpers);
end;
procedure TMyApp.ShowInvoicePreview(var Scope: Variant);
var
LContent: RawUTF8;
begin
Scope := _ObjFast([...]);
LContent := GetUserInvoicePreview(Scope);
_ObjAddProps(['Result', LContent], Scope);
end;
Offline
This is almost perfect, I have only a problem: pass the data from function to method.
The user call NewInvoice method, so he can use a form the set all data of new invoice.
There are 2 buttons, with the first button he can call SaveInvoice function and save the new invoice with all data from html form. With second button he can call InvoicePreview function to have a preview ON AN OTHER browser tab.
With you code InvoicePreview function can call ShowInvoicePreview method and then show custom invoice but how can pass html data sent with InvoicePreview function to ShowInvoicePreview method?
I hope I explained myself.
Offline
Pages: 1