You are not logged in.
Pages: 1
In the mustache template, any {{"English text}} tag will be passed as OnStringTranslate('English text') to the corresponding callback for rendering.
Would you like fully translated file resources, e.g. per-language HTML view files?
I'm familiar with this method. However, I don't think it's a good solution. I believe the HTML view files classified by language would be better. But I have no experience in this area and can't offer you any constructive suggestions.
My current requirement is that the website needs to be accessible to users of multiple different languages. If the website is in a single language, it would be a bit troublesome.
Are there any mature internationalization solutions available at present? Solutions for multiple languages
Please define "incorrect".
On my side, it seems fine:
https://i.ibb.co/6crxNtFK/Screenshot-2025-08-06-at-17-58-47-IBlog-Application-Information.png
I did nothing. I used the "mvc-blog" example.
windows 11
Lazarus 4.0RC3 (rev lazarus_4_0RC3) FPC 3.2.2 x86_64-win64-win32/win64
#0 TWrapperContext.ContextFromRtti(nil, wUnknown, TRttiCustom($000000000169C3C0), '', '') at mormot.soa.codegen.pas:685
#1 TWrapperContext.ContextArgsFromMethod(nil, TInterfaceMethod (''; ''; ''; 0; []; []; 0; 0; 0; 0; nil; 0; 0; 0; 0; 0; 0; 0; 0; 0; []; 100398128; nil; (''); nil; (4, 0, 0, 0, 0, 0, 0, 0, 187, 179))) at mormot.soa.codegen.pas:886
#2 TWrapperContext.ContextFromMethod(TWrapperContext($0000000005FBF278), Failed to read data from register (while calculating location)) at mormot.soa.codegen.pas:938
#3 TWrapperContext.ContextFromMethods(TWrapperContext($0000000005FBF278), Failed to read data from register) at mormot.soa.codegen.pas:994
#4 ContextFromMethods(Failed to read data from register) at mormot.soa.codegen.pas:1128
#5 TMvcApplication.GetMvcInfo(TMvcApplication($0000000005FBF278), Failed to read data from register (while calculating location)) at mormot.rest.mvc.pas:2663
#6 TMvcRunWithViews.ComputeMvcInfoCache(TMvcRunWithViews($0000000005FBF278)) at mormot.rest.mvc.pas:2084
#7 TMvcRunOnRestServer.InternalRunOnRestServer(TMvcRunOnRestServer($00000000016018D0), TRestServerUriContext($0000000007499710), 'mvc-info') at mormot.rest.mvc.pas:2220
#8 TMvcRunOnRestServer.RunOnRestServerRoot(TMvcRunOnRestServer($0000000005FBF278), Failed to read data from register) at mormot.rest.mvc.pas:2298
#9 TRestServerUriContext.ExecuteSoaByMethod(TRestServerUriContext($0000000005FBF278)) at mormot.rest.server.pas:3264
This URL is incorrect
http://localhost:8092/blog/mvc-info
procedure TMvcApplication.Test(Ctxt: TRestServerUriContext);
var
CookieData: TCookieData;
begin
// There was an error in this place. Before, I could do it this way and it worked!
// After synchronizing the latest code, here are the issues.
if CurrentSession.CheckAndRetrieve(@CookieData, TypeInfo(TCookieData)) > 0 then;
end;
procedure TMvcApplication.Start(aRestModel: TRest);
begin
(aRestModel as TRestServerDB).ServiceMethodRegister('Test', Test, True, [mGET]);
end;
Thank you very much for your efforts! I'm really happy to see how powerful mormot has become.
type
Tzerossl = class
private
FAcmeClient: TAcmeClient;
FICryptCert: ICryptCert;
FChallengeRec: ^TAcmeChallenge;
protected
procedure DoChallenges(Sender: TObject; const Domain, Key, Token: RawUtf8);
public
constructor Create;
destructor Destroy; override;
procedure start;
procedure CheckCertificate(Sender: TObject);
procedure CheckCertificatesBackground;
published
end;
implementation
const
ACME_ZEROSSL_URL = 'https://acme.zerossl.com/v2/DV90';
ACME_CHALLENGE_PATH = '/.well-known/pki-validation/';
procedure Tzerossl.DoChallenges(Sender: TObject; const Domain, Key, Token: RawUtf8);
begin
if Key <> '' then
begin
FChallengeRec^.Token := Token;
FChallengeRec^.Key := Key;
end;
end;
constructor Tzerossl.Create;
begin
inherited Create;
New(FChallengeRec);
FChallengeRec^ := Default(TAcmeChallenge);
FICryptCert := Cert('x509-es256');
FAcmeClient := TAcmeClient.Create(nil, FICryptCert, ACME_ZEROSSL_URL, 'tempEmail@temp.com', 'www.temp.com');
// FAcmeClient.OnChallenges := @DoChallenges;
end;
destructor Tzerossl.Destroy;
begin
if Assigned(FChallengeRec) then
begin
Dispose(FChallengeRec);
FChallengeRec := nil;
end;
FAcmeClient.Free;
inherited Destroy;
end;
procedure Tzerossl.start;
var
Terminated: boolean = False;
SSLDir: TFileName;
const
WaitForSec = 30;
PrivateKeyPassword = 'tempPwd';
begin
SSLDir := IncludeTrailingPathDelimiter(GetCurrentDir) + 'ssl' + PathDelim;
if not DirectoryExists(SSLDir) then
ForceDirectories(SSLDir);
if FAcmeClient.RegisterAndWait(@DoChallenges, SSLDir + 'mycert.pen', SSLDir + 'privkey.pem', PrivateKeyPassword, WaitForSec, @Terminated) = TAcmeStatus.asValid then
begin
// ok
end;
end;
procedure Tzerossl.CheckCertificate(Sender: TObject);
var
ExpiryDate: TDateTime;
SSLDIR: TFileName;
CertFile: TFileName;
const
RenewBeforeDays = 30;
begin
SSLDIR := IncludeTrailingPathDelimiter(GetCurrentDir) + 'ssl' + PathDelim;
CertFile := SSLDIR + 'mycert.pen';
if not FileExists(CertFile) then Exit;
if not FICryptCert.LoadFromFile(CertFile) then Exit;
ExpiryDate := FICryptCert.GetNotAfter;
if ExpiryDate < (NowUtc + RenewBeforeDays) then
start;
end;
procedure Tzerossl.CheckCertificatesBackground;
begin
TLoggedWorkThread.Create(TSynLog, 'CheckCertificate', self, @CheckCertificate, nil, False);
end;
Right now I’m using a ZeroSSL certificate instead of a Let’s Encrypt one. The snippets above show some code, but there’s no documentation and I don’t know how to write it. I’m using TMVCApplication and I need help
#0 ntdll:RtlInitializeResource+1251 at :0
#1 ntdll:RtlRaiseStatus+1167 at :0
#2 ntdll:RtlEnterCriticalSection+242 at :0
#3 InitThreadNumber(PSynLogThreadInfo($000000000A7EFFD8)) at mormot.core.log.pas:4628
#4 TSynLog.LockAndDisableExceptions(Failed to read data from register) at mormot.core.log.pas:4716
#5 TSynLog.LogInternalFmt(TSynLog($00000000014DCB40), sllTrace, $000000010057AAF8^: 'UnSubscribe(socket=% seq=%) cnt=% %', PVarRec($000000000A307A98), 4, TObject($00000000014E6930)) at mormot.core.log.pas:5782
#6 TSynLog.DoLog(Internal dereference error, Failed to read data from register, Internal dereference error, Failed to read data from register (while calculating location), Failed to read data from register, Failed to read data from register) at mormot.core.log.pas:5261
#7 TWinIocp.Unsubscribe(Failed to read data from register, Internal dereference error) at mormot.net.sock.windows.inc:1947
#8 TPollAsyncSockets.Stop(TPollAsyncSockets($00000000015075B0), TPollAsyncConnection($000000000AB193B0), 'Fatal Error') at mormot.net.async.pas:1751
#9 TPollAsyncSockets.CloseConnection(TPollAsyncSockets($00000000015075B0), nil, 'Fatal Error') at mormot.net.async.pas:2010
windows11 lazarus 4.0
unit mormot.core.log;
procedure InitThreadNumber(nfo: PSynLogThreadInfo);
GlobalThreadLock.Lock; // It seems that the problem lies with this method.
windows11 lazarus 4.0RC
I can't reproduce it - it work as expected at least on fpc 3.2.2.
edit: ... and mormot 2.3.10775
For testing, I downloaded the latest Lazarus 4.0 RC + mORMot ('2.3.11235'), but I still reproduced the error. I'm not sure if it's my issue or if the code itself is designed that way — it seems necessary to explicitly add the freeing code on exit.
I added the freeing code at the end before exiting, and then the problem did not occur.
Steps to reproduce the error:
Create a new form application, call the units from the mvc-blog example and other necessary units
Run the form application and start it
Open https://localhost/blog/default
Close the form
An error dialog pops up, reproducing the error.
uses
MVCModel, MVCViewModel;
var
Form1: TForm1;
aModel: TOrmModel;
aServer: TRestServerDB;
aApplication: TBlogApplication;
aHTTPServer, aHTTPSServer: TRestHttpServer;
LogFamily: TSynLogFamily;
implementation
{$R *.lfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
aModel := CreateModel;
aServer := TRestServerDB.Create(aModel, ChangeFileExt(Executable.ProgramFileName, '.db'));
aServer.DB.Synchronous := smNormal;
aServer.DB.LockingMode := lmExclusive;
aServer.Server.CreateMissingTables;
aApplication := TBlogApplication.Create;
aApplication.Start(aServer);
aHTTPServer := TRestHttpServer.Create('8092', aServer, '+', HTTP_DEFAULT_MODE, nil, 16, secNone, '', '', HTTPSERVER_DEBUG_OPTIONS);
aHTTPSServer := TRestHttpServer.Create([aServer], '443', 32, secTLS, HTTPSERVER_DEBUG_OPTIONS,
'C:\Users\ssl\mycert.pfx',
'C:\Users\ssl\privkey.pem',
'|&SSSv;"f',
'C:\Users\ssl\cert.pem');
aHTTPSServer.RootRedirectToURI('blog/default');
aServer.RootRedirectGet := 'blog/default';
aHTTPServer.RootRedirectToURI('blog/default'); // redirect / to blog/default
aServer.RootRedirectGet := 'blog/default'; // redirect blog to blog/default
end;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
aHTTPServer.Free;
aHTTPSServer.Free;
aApplication.Free;
aServer.Free;
end;
implementation
{$R *.lfm}
var
aModel: TOrmModel;
aServer: TRestServerDB;
aApplication: TBlogApplication;
aHTTPServer: TRestHttpServer;
aHTTPServer443: TRestHttpServer;
LogFamily: TSynLogFamily;
procedure TForm1.Button1Click(Sender: TObject);
begin
aModel := CreateModel;
aServer := TRestServerDB.Create(
aModel, ChangeFileExt(Executable.ProgramFileName, '.db'));
aServer.DB.Synchronous := smNormal;
aServer.DB.LockingMode := lmExclusive;
aServer.Server.CreateMissingTables;
aApplication := TBlogApplication.Create;
aApplication.Start(aServer);
aHTTPServer443 := TRestHttpServer.Create([aServer], '443', 32, secTLS, HTTPSERVER_DEBUG_OPTIONS,
'C:\Users\aaa\Desktop\ssl\mycert.pfx',
'C:\Users\aaa\Desktop\ssl\privkey.pem',
'|sBcaVv;"f',
'C:\Users\aaa\Desktop\ssl\cert.pem');
aHTTPServer443.RootRedirectToURI('blog/default');
aServer.RootRedirectGet := 'blog/default';
aHTTPServer := TRestHttpServer.Create('8092', aServer, '+',
HTTP_DEFAULT_MODE, nil, 16, secNone, '', '', HTTPSERVER_DEBUG_OPTIONS);
aHTTPServer.RootRedirectToURI('blog/default'); // redirect / to blog/default
//aHTTPServer.RootRedirectToURI('blog/default', True, True);
aServer.RootRedirectGet := 'blog/default'; // redirect blog to blog/default
end;
Convert the mvc-blog example into a program with a form, without making any other changes. Start the program, then open the web page, and then exit the program. At this point, the following error message will appear: "Access violation writing to address $0000000000000024."
I am using Lazarus 3.0.
Of course, you need to access it via https. https://localhost/blog/default
I need to execute the TJsonClient.Request method inside a thread pool task, but I have a problem: how can I pass an array of const parameter?
In such a situation, how would you operate?
I looked at the official code and found that it directly used the addresses of records and classes.However, both records and classes cannot pass an array of const.
procedure TCustomThreadPool.Task(aCaller: TSynThreadPoolWorkThread; aContext: pointer);
begin
TJsonClient.Request(const Method, ActionFmt: RawUtf8;
const ActionArgs, QueryNameValueParams, HeaderNameValueParams: array of const;
var Res; ResInfo: PRttiInfo;
const CustomError: TOnJsonClientError = nil);
end;
There is not enough RTTI on FPC 3.2.2 to define the record fields.
You need to describe your record with a text definition in your code.
This is what is done for example with our OpenAPI generator.
It's done! Thank you.
On which compiler?
lazarus 3.0
FPC 3.2.2
WIN64
I'm not sure if what I wrote is correct. DataRec can't get the data.
type
TDataRec = packed record
userId: integer;
id: integer;
title: RawUtf8;
completed: boolean;
end;
PDataRec = ^TDataRec;
TDataRecArr = array of TDataRec;
procedure TestJsonClient;
implementation
procedure TestJsonClient;
var
JsonClient: TJsonClient;
DataRecArr: TDataRecArr;
DataRec: TDataRec;
begin
FillChar(DataRecArr, SizeOf(DataRecArr), 0);
JsonClient := TJsonClient.Create('https://jsonplaceholder.typicode.com');
JsonClient.Request('GET', 'todos/%', [1], [], [], DataRec, TypeInfo(TDataRec), nil);
end;
The following is the returned data.
https://jsonplaceholder.typicode.com/todos/1
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
This is really a headache-inducing issue. The Mustache official specification should resolve this problem, or we could implement this functionality directly in the Pascal code. Some online Mustache implementations already treat empty strings as true, and I think this doesn't pose any security risk because {{#section}}...{{/section}} and {{^section}}...{{/section}} are paired constructs. At least in general understanding, they are supposed to work that way; otherwise, it would truly cause confusion.
For just this small feature, I really have to write some code to handle it—it’s definitely not convenient.
I used the mvc-blog example and modified the following code in the articlerow.partial file, but the functionality did not meet my expectations:
<h2 class="blog-post-title"><a href=articleView?id={{id}}>{{Title}}</a></h2>
<h2 class="blog-post-title"><a href=articleView?id={{id}}>{{Title}}{{^Title}}000{{/Title}}</a></h2>
I just checked the mvc-blog source code and found that {{^ }} (the inverted section) is always used with Boolean, Array, or null types. It seems it’s not used with strings. Could it be that it doesn’t work with strings?
I also looked up the inverted.json file but it seems there’s no operation for empty strings.
However, if the following code is rendered on the frontend with JavaScript calling Mustache.min.js, it works fine. I guess it works because my code is similar and also rendered on the frontend:
<h2 class="blog-post-title"><a href=articleView?id={{id}}>{{Title}}{{^Title}}000{{/Title}}</a></h2>
I saw the mormot.core.mustache unit’s RenderContext code and it looks like empty strings are not supported:
procedure TSynMustache.RenderContext(Context: TSynMustacheContext;
TagStart, TagEnd: PtrInt);
mtInvertedSection:
// display section for no key, false value, or empty list
if Context.AppendSection(t^.ValueSpace, t^.Value) <> msNothing then
begin
TagStart := t^.SectionOppositeIndex;
continue; // ignore whole section
end;
I haven’t looked deeper into the code yet, and I might have said something wrong.
I don’t know where I went wrong; the code is still not executing as I expected.
The name field in the MongoDB database is of string type and can be empty "".
{{name}} is correct — it shows empty if the value is empty, or if I write a character in the database, it displays correctly.
I am using TMVCApplication, and these templates are all placed in the frontend HTML.
{
"Result": {
"Data": [
{
"Name": ""
"Sex": "Male"
},
{
"Name": "1"
"Sex": "Male"
}
{
"Name": "2"
"Sex": "Male"
}
]
}
}
None of the following work:
{{#if name, "=", ""}}No name{{/if}}
{{#if name =, ""}}No name{{/if}}
{{#if name,"=",""}}No name{{/if}}
{{#if name=""}}No name{{/if}}
{{^name}}No name{{/name}}
{{#Equals name,""}}No name{{/Equals name,""}}
{{#Equals name,""}}No name{{/Equals}}
The link you gave me, I also looked at it, but I still don't understand.
Is it that strings cannot be compared?
I wrote a RegisterExpressionHelpers myself and got it working, but I still want to understand where I went wrong.
Today I checked, and if Name is empty, the code below doesn't work at all.
{{#Result.Data}}
{{^Result.Data.Name}}Unknown{{/Result.Data.Name}}
{{/Result.Data}}
{{#Result.Data}}
{{^Name}}Unknown{{/Name}}
{{/Result.Data}}
Differences between backend Mustache rendering in Mormot and frontend Mustache.min.js rendering:
Backend data:
{
"Result": {
"Data": [
{
"Name": "John"
},
{
"Sex": "Male"
}
]
}
}
Backend Mustache rendering:
{{#Result.Data}}
{{Name}}{{^Result.Data}}Unknown{{/Result.Data}}
{{/Result.Data}}
Frontend Mustache.min.js rendering:
{{#Result.Data}}
{{Name}}{{^Data}}Unknown{{/Data}}
{{/Result.Data}}
One is a relative path, and the other is an absolute path
While writing the code, I found a small issue. I want to share it here so everyone can avoid spending hours troubleshooting the same problem.
Mustache.min.js is the official code I downloaded; my testing is not rigorous enough
TWebServerHsts = (
wshOff,
wshOn,
wshIncludeSubDomains,
wshIncludeSubDomainsPreload);
In TMVCApplication, how to use `TWebServerHsts`?
I created pull request to fix minor ACME client bug:
https://github.com/synopse/mORMot2/pull/367
First of all, thank you very much for sharing
I have reviewed your code and noticed that you associate tmvcapplication and acme through reading and writing local certificate files, rather than linking them directly in the code. Could this cause any issues, such as file access conflicts?
Also, it seems you did not use the RegisterAndWaitFolder CompleteDomainRegistration method. Have you tested your code to ensure it runs completely without any problems?
Sorry, I forgot to check before sending the content.
procedure ACMEStart;
var
F: TFileName;
ES: TAcmeLetsEncryptServer;
I: integer;
Status: TAcmeStatus;
Cert, PrivateKey: RawUtf8;
begin
RegisterOpenSsl;
F := IncludeTrailingPathDelimiter(GetCurrentDir) + 'sslFolder';
ES := TAcmeLetsEncryptServer.Create(TSynLog, F,
ACME_LETSENCRYPT_DEBUG_URL,
'x509-es256', 'jf93v83');
try
ES.LoadFromKeyStoreFolder;
for I := Low(ES.Client) to High(ES.Client) do
with ES.Client[I] do
begin
RegisterAndWaitFolder(F, F, F, 'jf93v83', 3);
repeat
Status := CheckChallengesStatus;
Sleep(1000);
until Status <> asPending;
if Status = asValid then
begin
Status := ES.Client[I].CompleteDomainRegistration(Cert, PrivateKey, 'jf93v83');
end;
end;
ES.CheckCertificatesBackground;
ES.Redirect('xxx.com', 'https://xxx.com');
ES.Redirect('www.xxx.com', 'https://www.xxx.com');
finally
ES.Free;
end;
end;
Below is the JSON file, to be used by the LoadFromKeyStoreFolder method.
{
"contact": "mailto:admin@xxx.com",
"subjects": [
"xxx.com"
"www.com"
]
}
1.Since I don't have a domain name or a public IP, I cannot perform testing. I’m not sure if what I wrote is correct. Is there anything else I should pay attention to?
2.How does ACME integrate with TMvcApplication? Should I directly call RegisterAndWaitFolder to save the certificate files, or how should it be handled?
HttpServer := TRestHttpServer.Create([RestServerDB], '443', 32, secTLS, HTTPSERVER_DEFAULT_OPTIONS,
'C:\Users\FBI\Desktop\BOOK\1\ssl\mycert.pfx',
'C:\Users\FBI\Desktop\BOOK\1\ssl\privkey.pem',
'|&VwVx;2S',
'C:\Users\FBI\Desktop\BOOK\1\ssl\cert.pem'
);
FRestHttpServer.DomainHostRedirect('xxx.com', 'root');
FRestHttpServer.RootRedirectToURI('xxx.com', 'blog/default', true, true);
Pages: 1