xpodev / ez-web

2 stars 0 forks source link

Dev/fix template system #37

Closed binyamin555 closed 4 months ago

binyamin555 commented 4 months ago

I have fixed the page data injection code and it now allows adding more parameters which will be handled by FastAPI.

In the case where the render function omits the page parameter, the page data will not be passed.

The page data parameter(s) can be identifies via annotation, as page data parameter(s) are declared using the PageData type annotation that may be imported from ez.templates.

from jsx.html import Div

from ez.templates import template, PageData

@template("page1")
def page1(my_page: PageData, query_param: str):
  return Div(
    my_page.id, my_page.title, my_page.content, my_page.slug
  )

@template("page2")
def page2(query_param: str):
  return Div(
    "This template does not support page data. Data is fetched separately."
  )

If the template slug contains a path parameter - such as /product/{product_id} - it can be accessed by having a parameter with the same name (in the example, a parameter named product_id).

neriyaco commented 4 months ago

It’s very specific to page but it looks good. In the future we’ll implement something more generic so we can inject more dependencies.

Don’t change it, just merge

binyamin555 commented 4 months ago

Don't merge yet