Using frappe.db.get_value in jinja html

In order to display the default company name in the navbar, I put this code in the navbar.html in frappe/frappe/public/js/frappe/ui/toolbar/navbar.html.

<span class="company-name-header">{{ frappe.db.get_value('Global Defaults', None, 'company_name') }}</span>

But it doesn’t display the company name. And there is error when I run bench build --app frappe:

SyntaxError: Unexpected token (2:481)
1 :
2 :         frappe.templates['navbar'] = '   <div class="navbar navbar-default navbar-fixed-top" role="navigation">  <div class="container"> #and the rest of the html here...

Is the code I use wrong?
What is the correct way/code to use ?
Thank you.

I changed the quote sign in the code to

<span class="company-name-header">{{ frappe.db.get_single_value("Global Defaults", "default_company") }}</span>

and now the navbar shows

[object Promise]

If I use this code:

<span class="company-name-header">
    {% set comp = frappe.db.get_single_value("Global Defaults", "default_company") %}
    {{ comp }}

The bench build doesn’t show error but the whole navbar is not displayed on the desk.

I’ll give you a hint: the file you’re trying to modify doesn’t use Jinja.

I was thinking it uses Jinja because I saw these:

{{ avatar }}
{%= frappe.user.full_name() %}
{%= __("My Profile") %}

Then please how to solve my problem?
I guess I have to use js, which I don’t know :slight_smile:

You need to modify the toolbar.js file as well.



If you don’t want to change core file you can check this app.

1 Like

Thanks @Maheshwari_Bhavesh,

I have other changes so I don’t use your app.
But thanks anyway.