Website_context in hooks.py of own app not working

Hello,

i have the following problem.
I made a simple app and installed it to my site. The purpose of the app is simply providing another favicon and splash-screen.

Then i created a public folder, which was correctly integrated via “bench build” into the assets. Into this folder i copied my elements.

The i introduced this into my hooks.py of the app.

website_context = {
    "favicon":     "/assets/acmeerp/images/favicon.png",
    "splash_image": "/assets/acmeerp/images/splash.png"
}

normally the splash and the favicon should be replaced with the given elements here. But nothing happens.

For testing i changed the website_context in the hooks.py of erpnext. Then my splash and favicon has been adjusted. But i wanted not to modify the hooks.py of erpnext.

I wanted to get this done in my app.

Maybe someone has an idea about this.

No ideas about it?

Or is it by design, that the website_context cant be modified in the hooks.py of an app?

I think only the first splash icon is considered.

Maybe the last one should.

or maybe, why make whitelabeling easy :slight_smile:

Because i can set the website_context in the hooks.py of erpnext itself whitelabeling is easy.

But not being able to set the website_context in the hooks.py of the app is a weak design, because the philosophy of the apps is doing things without hitting the kernel. :slight_smile:

An interesting question is really the sequence of action while working down the hooks.py of more than one installed apps.

Is there a certain order we must consider?
Or can the order be influenced by the developer?

This can be of interest, when hooking into events of the document.

In cases where more than one values is set (for e.g. splash), the only way to decide is by setting a rule, either the first one, or the last one. Currently the app that is installed first, gets access to splash, that is “erpnext”, maybe it could be the last one.

Can’t see how this is weak design!

@Idat-Consulting
You can try below code.
put below code in your app directory (Ex. yourapp/template/page/utils.py)

import frappe
from frappe import _
def update_website_context(context):
	if frappe.auth.get_logged_user() != "Guest":
		context["check_student"]=True
	else:
		context["check_student"]= False
	context["student_menu"]= [
			{"label": _("Dashboar"), "url": "dashboard", "class": "cart-count"},
			{"class": "divider"}
		]

	# Set Techbeeo Logo on reload
	via_hooks = frappe.get_hooks("website_context")
	for key in via_hooks:
		context[key] = via_hooks[key]
		if key not in ("top_bar_items", "footer_items", "post_login") \
				and isinstance(context[key], (list, tuple)):
			context[key] = context[key][-1]

	if not frappe.local.conf.get("website_context"):
		frappe.local.conf['website_context'] = {}
	frappe.local.conf['website_context'].update(context)

and add below code in your hooks.py file

website_context = {
	"favicon": 	"/assets/university/images/favicon.png",
	"splash_image": "/assets/university/images/splash.png"
}
update_website_context = "yourapp.templates.pages.utils.update_website_context"

So you can call any function that you put in your hooks.py just like that? Because I did the exact thing but my function just "print"s something to the console. But that isn’t showing up. Where is documented that you can implement your own functions like that?