Frappe.get_all no ouput

Hello Community

I`m trying to get the entire item groups from database as it is ( Parent , Child , Route and name) then list all of them in tree menu in website

In my case i`v more than 150 item group so the normal website navbar allows to be only 2 levels and i have around 5 levels

so if some one help me to get all of them into frappe/frappe/templates/includes/navbar/navbar.html eg

i can handle them

so how can i get them into this file ???

1 Like

Have you found any solution? The first level generally goes for “Products”, so practically there is only one level to group the products for the website if there is no way to put grandchildren for the children.

Actually i`m planning to get item groups from database into a py file then create a html file that can list the output of this file

so if it done i can import this html file into website header or footer as a menu and can style it as we wish

so lets start

or we can achieve this with jinja ??

Please help !

i`m trying the following in footer_power.html

{% set c = frappe.get_doc("Item Group", "Products") %}
       {{ c.item_group_name or '' }}
       {{ c.route or '' }}

and every thing working well

but when i try

{% set c = frappe.get_all('Item Group', filters={'is_group': 1}, fields=['item_group_name ', 'route']) %}
       {{ c.item_group_name or '' }}
       {{ c.route or '' }}

i get no output so whats wrong ??

1 Like

any idea ??

Unlike the frappe.get_doc function, frappe.get_all returns a dict object not a doc (see: Developer Cheetsheet).
Therefore, if your result is a single record, you need to use the following code:
{{ c[0].item_group_name or '' }}
if you expect more than a record, you can loop through the list as in:
{% for c in frappe.get_all('Item Group', filters={'is_group': 1}, fields=['item_group_name ', 'route']) %}
{{ c.item_group_name }}
{% endfor %}

1 Like