#2 Re: mORMot 1 » Mustache IF helper fix » 2016-05-13 13:37:35

... and line 1171 in TSynMustacheContextVariant.GetValueCopyFromContext :

  if (ValueName='') or (ValueName[1] in ['1'..'9','"','{','[']) or
     (ValueName='true') or (ValueName='false') or (ValueName='null') then

... need to include the "0" character :

  if (ValueName='') or (ValueName[1] in ['0'..'9','"','{','[']) or
     (ValueName='true') or (ValueName='false') or (ValueName='null') then


... or else "{{#if tval=0}} wouldn't work!

#3 mORMot 1 » Mustache IF helper fix » 2016-05-13 13:09:52

orclstemu
Replies: 3

I noticed the following test code didn't work:

mustache := TSynMustache.Parse( stringtoutf8('1+3={{tval}} - is it 4? {{#if tval=45}}yes!{{/if}}'));
s := utf8tostring(mustache.RenderJSON( stringtoutf8('{ "tval":45}'), nil, Mustache.HelpersGetStandardList ));
debug_alert(s);


.. turned out the problem was in SynMustache.pas on line 1221:

   valArr.InitArray([GetValueCopyFromContext(Copy(nam,1,j-1)),
            Copy(nam,j,k-j),GetValueCopyFromContext(Copy(nam,k+1,maxInt))],JSON_OPTIONS[true]);

needs to be:

   valArr.InitArray([GetValueCopyFromContext(Copy(nam,1,j-1)),
            Copy(nam,j,k-j),GetValueCopyFromContext(Copy(nam,k,maxInt))],JSON_OPTIONS[true]);


Thanks for the library! I use it together with DCEF3 to generate all kind of reports in my application!

Regards,
Stefan

Board footer

Powered by FluxBB