#2 mORMot 1 » How to set a list of data to TSynMustache Template » 2016-02-21 16:13:29

Weled1980
Replies: 2

Hello,

I have the following template:

{{Title}}

{{#Favorite}}
<strong><a href="{{Link}}">{{Name}}<a></strong><br />
{{/Favorite}}

and here is my (simplified) data classes:

type
  TFavorite = class
  public
    property Name: String read fName write fName;
    property Link: String read fLink write fName;
  end;

  TFavorites = class(TList<TFavorite>);

  THTMLFile = class
  public
    property Title: String read fTitle write fTitle;
    property Favorites: TFavorites read fFavorites;
  end;

Here is my (simplified) function in set the data to the TSynMustache instance:

var
  Mustache: TSynMustache;
  HTMLFile: THTMLFile; 
  Doc: Variant;
begin
  Mustache := TSynMustache.Parse(//template//);

  TDocVariant.New(Doc);
  TDocVariantData(Doc).AddValue('Title', HTMLFile.Title);
  TDocVariantData(Doc).AddValue('Favorites', HTMLFile.Favorites);  // <----- !!!

  Result := Mustache.Render(Doc);
end;

I do not know how to set a list of data (HTMLFile.Favorites).

Many thanks for the help!!!

Board footer

Powered by FluxBB