RoutesΒΆ

Routes are defined by using ~ as a prefix. The routes will be used by a dispatcher and linkto components.

#import components
#inherit base

~routes:
  list: '/blog/posts'
  show: '/blog/post/{id}'
  edit: '/blog/post/{id}/edit'

*content:
  ul:
    li:
      base-linkto action='list': List
    li:
      base-linkto action='show' id=1: Details
    li:
      base-linkto action='edit' id=1: Edit

The rendered result:

<!DOCTYPE html>
<html>
  <head>
    <title>zml</title>
  </head>
  <body>
    <ul>
      <li><a href="/blog/posts">List</a></li>
      <li><a href="/blog/post/1">Details</a></li>
      <li><a href="/blog/post/1/edit">Edit</a></li>
    </ul>
  </body>
</html>

The linkto-component of the base namespace is simply defined:

#namespace base=doonx.org/base

*linkto:
  a href=_path(action, _params):
    {_children[0]}

The _path function is a core function of the zml implementation. It will return an url path by interpolating the parameters into the route path definition. The routevars wrapped by moustaches in the route-section (~) with the corresponding action name will be replaced by the values of the second function parameter of the _path function.

The _params context property contains all parameters of a component. F.e. the following line will use the linkto-component with the parameters action and id. The component can access the parameters by using the _params context property. The linkto-component will forward the _params property as a parameter of the _path function.

base-linkto action='edit' id=1