template
TemplateRouter
from dara.core.visual.template import TemplateRouter
class TemplateRouter()
The TemplateRouter is a python based representation of the router that serializes into a structure that is read into the javascript routing components to build out the routing
Methods
add_route
def add_route(name: str,
route: str,
content: ComponentInstance,
icon: Optional[str] = None,
include_in_menu: Optional[bool] = True,
on_load: Optional[Action] = None)
Add a single route to the router.
Arguments:
name
: the name for the route (what will be displayed on links to the page)route
: the url for the routecontent
: a component instance to display when this route is activeicon
: an optional icon to display with the linkinclude_in_menu
: an optional flag for not including the route in the links
links
@property
def links()
Return the router as a set of links for the UI to consume
content
@property
def content()
Return the router as a set of content pages for the UI to consume
from_pages
@staticmethod
def from_pages(pages: List[Page])
Create a template router from a list of page objects
Arguments:
pages
: the list of pages
TemplateBuilder
from dara.core.visual.template import TemplateBuilder
class TemplateBuilder()
The TemplateBuilder class lets you build a Template object up piece by piece using helper methods that aid setup and point users in the right direction. Before passing it into the main application you should call to_template() to perform final validation and build the Template object.
Attributes
- layout: Optional[ComponentInstance]
- name: Optional[str]
- _router: Optional[TemplateRouter]
Methods
__init__
def __init__(name: Optional[str] = None)
Arguments:
name
: the name for the template
add_router
def add_router()
Add a router to the template. The router instance is returned and can then be configured as the user wishes. Currently each template can only have one router registered with it.
add_router_from_pages
def add_router_from_pages(pages: List[Page])
Add a router to the template based on an apps pages. The router instance is returned and can then be configured as the user wishes. Currently each template can only have one router registered with it.
to_template
def to_template()
Perform final validation and convert the TemplateBuilder to a Template class ready for the application to work from.