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

Allow override of the index template #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Benoss
Copy link

@Benoss Benoss commented Nov 11, 2023

This small change allow to quickly override the Jinja template by proving your own base template.
If you don't set app.config["CLICK_WEB_MAIN_TEMPLATE" there is no changes to the current behaviour of the blueprint

Example folder structure:

main.py (contain a click app called cli)
webcli.py (the file bellow)
webcli/static/custom.css (the css override for the app)
webcli/templates/my_main_clickweb.html.j2 (A modified version of template show_tree.html.j2)

from click_web import create_click_web_app
from flask import Blueprint
import main

app = create_click_web_app(main, main.cli)
# Expect any custom static and template folder to be located in same folder as this script
# Make custom folder reachable by "custom/static" url path and add templates folder
custom_folder_blueprint = Blueprint(
    "custom", __name__, static_url_path="/static", static_folder="webcli/static", template_folder="webcli/templates"
)
app.register_blueprint(custom_folder_blueprint)

# Set CUSTOM_CSS in flask config so click-web will use it.
app.config["CUSTOM_CSS"] = "custom.css"
app.config["EXPLAIN_TEMPLATE_LOADING"] = True
# Override the main template to one in webcli/templates/my_main_clickweb.html.j2 directory
app.config["CLICK_WEB_MAIN_TEMPLATE"] = "my_main_clickweb.html.j2"`  

if __name__ == "__main__":
    app.run(debug=True, port=5000)

Example usage:
app.config["CLICK_WEB_MAIN_TEMPLATE"] = "my_main_clickweb.html.j2"
@fredrik-corneliusson
Copy link
Owner

Nice, would it be possible to add an example for this like example/custom/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants