Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added add_template_global function to JinjaTemplate. #738

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions robyn/templating.py
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
from abc import ABC, abstractmethod
from typing import Callable

from robyn import status_codes

Expand Down Expand Up @@ -28,5 29,10 @@ def render_template(self, template_name, **kwargs) -> Response:
headers=Headers({"Content-Type": "text/html; charset=utf-8"}),
)

def add_template_global(self, func: Callable, name: str | None = None):
Copy link
Member

@sansyrox sansyrox Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @JarriqTheTechie 👋

Just two suggestions

if not callable(func):
raise TypeError("Must be callable.")
self.env.globals[name or func.__name__] = func


__all__ = ["TemplateInterface", "JinjaTemplate"]
Loading