Skip to content

Add template_file config and document page customization#1923

Open
rgaiacs wants to merge 7 commits into
jupyterhub:mainfrom
rgaiacs:1907-custom-ui
Open

Add template_file config and document page customization#1923
rgaiacs wants to merge 7 commits into
jupyterhub:mainfrom
rgaiacs:1907-custom-ui

Conversation

@rgaiacs

@rgaiacs rgaiacs commented Jan 30, 2025

Copy link
Copy Markdown
Contributor

Closes #1907

We might want to make add a new traitlets for users to provide their own Jinja template that will be used in

"page.html",
from
self.render_template(
"page.html",
page_config=self.page_config,
extra_footer_scripts=self.settings["extra_footer_scripts"],
opengraph_title=self.opengraph_title,
)

@rgaiacs rgaiacs requested a review from yuvipanda January 30, 2025 13:37
@rgaiacs rgaiacs self-assigned this Jan 30, 2025
Comment thread docs/source/customizing.rst Outdated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

BinderHub uses `Jinja <https://jinja.palletsprojects.com/en/stable/>`_ as template engine
to process the page template `binderhub/templates/page.html <https://github.com/jupyterhub/binderhub/blob/main/binderhub/templates/page.html>`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it'd be helpful to also highlight the important parts of the template- is <div id="root"></div> the critical bit?

Comment thread docs/source/customizing.rst Outdated
release: {{ .Release.Name }}
data:
{{- (.Files.Glob "files/*").AsConfig | nindent 2 }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is additional Helm configuration needed to mount the file in the ConfigMap into the BinderHub pod?

@rgaiacs

rgaiacs commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

I will address the comments in a couple of weeks.

@rgaiacs rgaiacs force-pushed the 1907-custom-ui branch 2 times, most recently from 151e661 to dd7c67f Compare March 28, 2025 16:19
@rgaiacs rgaiacs requested a review from manics March 28, 2025 16:35
@rgaiacs

rgaiacs commented Mar 28, 2025

Copy link
Copy Markdown
Contributor Author

Sorry for the delay to return to this.

I address the comments.

Do I need to add some tests? If yes, can I have some help? Thanks!

@agahkarakuzu

Copy link
Copy Markdown

@rgaiacs thanks for this PR!

How complicated would it be to customize components like HowItWorks.jsx, and have the template page use the built dist to control what gets rendered inside <div id="root"></div>?

For example, I can easily add header/footer

image

but I cannot figure out a way to "replace" the binder logo with this design.

Also, I think extra_static_path no longer takes effect, or at least I could not figure out how to link assets I used to mount at /etc/binderhub/custom/static.

@rgaiacs

rgaiacs commented Apr 28, 2025

Copy link
Copy Markdown
Contributor Author

Hi @agahkarakuzu,

the challenge to customise any file in binderhub/static/js is due to how the JavaScript works.

We are using webpack to merge all JavaScript files into a single bundle.js file that is we reference in the HTML that we send to the user, see

<script src="{{static_url("dist/bundle.js")}}"></script>

How complicated would it be to customize components like HowItWorks.jsx

If you want to change any of the JavaScript files, for example HowItWorks.jsx, you will have to

  1. re-run webpack to create a new bundle.js.
  2. create a new volume that overwrite the default bundle.js with the one that you created.

@agahkarakuzu

Copy link
Copy Markdown

Thanks @rgaiacs ! I actually created a new bundle.js. Would simply mounting the new distribution override the existing one?

@rgaiacs

rgaiacs commented Apr 28, 2025

Copy link
Copy Markdown
Contributor Author

Would simply mounting the new distribution override the existing one?

It should.

@agahkarakuzu

agahkarakuzu commented Apr 28, 2025

Copy link
Copy Markdown

It did! https://binder.evidencepub.io

  - name: custom-templates
    mountPath: /usr/local/lib/python3.13/site-packages/binderhub/static/
    subPath: static

The mountPath is a bit dependent on the python version, but I was able to build the sources from modified content and have that content rendered.

Build sources are from https://github.com/evidencepub/binder-template/tree/preview. I'll add a github action to this repository to better streamline the builds.

@rgaiacs

rgaiacs commented Sep 9, 2025

Copy link
Copy Markdown
Contributor Author

One of the tests are with

FAILED binderhub/tests/test_registry.py::test_get_image_manifest[False] - OSError: [Errno 98] Address already in use

I believe the failure not related with this pull request.

@yuvipanda and @minrk this is blocking jupyterhub/mybinder.org-deploy#3186 and I would like to merge this earlier next week.

@consideRatio consideRatio changed the title Document how to customize page Add template_file config and document page customization Sep 9, 2025
@manics

manics commented Sep 15, 2025

Copy link
Copy Markdown
Member

Do we need the new template_file property? Can't we already override the template using template_path?

binderhub/binderhub/app.py

Lines 791 to 798 in 43ecb3a

template_path = Unicode(
help="Path to search for custom jinja templates, before using the default templates.",
config=True,
)
@default("template_path")
def _template_path_default(self):
return os.path.join(HERE, "templates")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Document how to customise index / root page

5 participants