3

I can see in Vibed's Diet source code, the void compileDietString(string diet_code, ALIASES...)(OutputStream stream__) function.

I see it takes up to an infinite amount of aliases, as a template parameter.

What are these aliases? I have trouble figuring out through the source, it uses a lot of concepts like traits and mixins which I don't really understand that well.

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Jeroen
  • 15,257
  • 12
  • 59
  • 102

1 Answers1

4

These parameters are passed over from render and renderCompat. From the documentation of renderCompat:

All following arguments must be pairs of a type and a string, each specifying one parameter. Parameter values can be passed either as a value of the same type as specified by the template arguments, or as a Variant which has the same type stored.

Example:

string title = "Hello, World!";
int pageNumber = 1;
res.renderCompat!("mytemplate.jd",
    string, "title",
    int, "pageNumber")
    (title, pageNumber);
Vladimir Panteleev
  • 24,651
  • 6
  • 70
  • 114
  • I still don't get how that works. What is the point of all of those variables at the end and how do they get interpreted? Also the full documentation doesn't use pairs: `render!("userinfo.jd", username)(res);` ~ http://vibed.org/docs#http-routing – Jeroen Apr 29 '14 at 19:18
  • 1
    `render` is not `renderCompat`. `render` uses compile-time introspection to query the identifier types and names. In `renderCompat`, they are specified explicitly. – Vladimir Panteleev Apr 29 '14 at 19:38
  • Oh I see now, so for the regular function you can just pass in the variables? Thanks. – Jeroen Apr 29 '14 at 19:54
  • Point of providing those variables as aliases is to expose them inside renderd Diet template in embedded D snippets. – Mihails Strasuns Apr 30 '14 at 17:37