Bsaidus wrote:Thanks igor for help, but it do not work for me.
You do not register the default helper, so "IF" is not available to you. You have to write it like this:
mustache.RenderJSON(Context, Nil, TSynMustache.HelpersGetStandardList)
All in all, I would not solve this during generation, but calculate it outside and then pass it. How to use Mustache is described in this article with source code.
With best regards
Thomas
Thank you Thomas, I'll read.
]]>Thanks igor for help, but it do not work for me.
You do not register the default helper, so "IF" is not available to you. You have to write it like this:
mustache.RenderJSON(Context, Nil, TSynMustache.HelpersGetStandardList)
All in all, I would not solve this during generation, but calculate it outside and then pass it. How to use Mustache is described in this article with source code.
With best regards
Thomas
Try to use the debugger to find out why it did not work.
For instance, put a breakpoint into the "if" helper, i.e. TSynMustache.If_().You will learn a lot about how it works.
I did, but it do not even enter there.
]]>You will learn a lot about how it works.
]]>Use:
<option value="111.222.333.111" {{#if host.mask="111.222.333.111"}} selected {{/if}}> 111.222.333.111 </option>
<option value="222.222.222.0" {{#if host.mask="222.222.222.0"}} selected {{/if}}>222.222.222.0</option>
Thanks igor for help, but it do not work for me.
// lazarus code
procedure TForm1.Button2Click(Sender: TObject);
var
Template,
Context,
Result: RawUTF8;
mustache: TSynMustache;
begin
Template := StringToUTF8(mmTemp.Text); // mmTemp = memo for template
Context := StringToUTF8(mmJson.Text); // mmJson = memo for json
mmRes.Append( UTF8ToString(Context) ); // mmRes = memo for resulting rendring
mustache := TSynMustache.Parse(Template);
mmRes.Append('-----------------------------------------------------------');
mmRes.Append(mustache.RenderJSON(Context));
end;
EX: from the fcl-mustache.
// json
{
"host":{
"name" : "uc1.uccenos.net",
"ip" : "123.33.32.1",
"mask" : "222.222.222.0",
"gateway" : "123.33.23.3"
}
}
//template
// depending on the mask value from json & make the adequate <Option> selected
<br/>
<ul>
<li>hostnam : {{host.name}}</li>
<li>ip : {{host.ip}}</li>
<li>mask : {{host.mask}}</li>
<li>gateway : {{host.gateway}}</li>
<select name="themask">
<option value="111.222.333.111" {{[IF(mask='111.222.333.111', 'selected','')]}}> 111.222.333.111 </option>
<option value="222.222.222.0" {{[IF(mask='222.222.222.0', 'selected','')]}}> 222.222.222.0 </option>
<option value="333.222.333.111" {{[IF(mask='333.222.333.111', 'selected','')]}}> 333.222.333.111 </option>
</select>
Thanks you.
]]>