Skip to content

Specialized View Rendering

Jacob Jensen edited this page Oct 13, 2017 · 1 revision

Specialized View Rendering

Views can render each other in specialized manners such as passing models etc.

The following functions allows for regular view retrieving/rendering (Compatible below v2.0.4)

  • auto view(string name, bool checkRoute = false)
    • Returns a generic view that can be cast to specific view types, however with v2.0.4 you can use viewSpecialized() instead of casting.
  • string retrieve(string name)
    • Retrieves the default html generated by the view to retrieve (name is the name of the view)
  • void render(string name)
    • Will render the view retrieved into the current view. (name is the name of the view to render)

The following functions allow for specialized view retrieving/rendering (Compatible with v2.0.4+)

It's preferred to use the following functions unless you retrieve view names from runtime variables.

  • void render(string name, string id, string placeHolder, string view)
    • Will render a view into the current view, but with another view rendered into the given placeholder.
  • string retrieve(string name)()
    • Does the same thing as string retrieve(string name) but the name is passed during compile-time.
  • void render(string name)()
    • Does the same as void render(string name) but the name is passed during compile-time.
  • void render(string name)(string id, string placeHolder, string view)
    • Does the same as void render(string name, string id, string placeHolder, string view) but the name is passed during compile-time.
  • string retrieve(string name, TModel)(TModel model)
    • Retrieves the html generated by the view to retrieve using its model (name is the name of the view)
  • void render(string name, TModel)(TModel model)
    • Will render the view retrieved into the current view using its model (name is the name of the view to render)
  • void render(string view, TModel)(string name, string id, string placeHolder, TModel model)
    • Will render a view into the current view, but with another view rendered using its model into the given placeholder.

Example

view1.dd

@[
  model:
    Foo
]

<p>@=model.bar;</p>

view2.dd

@{
    auto foo = new Foo;
    foo.bar = "Hello World!";
}

@:this.render!("view1", Foo)(foo);

Output of view2:

<p>Hello World!</p>
Clone this wiki locally