-
Hi, I try to generate a menu from db on the shell component configuring it with a name and a link. For that, I override the shell component. I copied the shell.handlebars file and changed only this: <ul class="navbar-nav ms-auto">
{{#each (to_array menu_item) as |menu|}}
<li class="nav-item">
<a class="nav-link text-capitalize" href="{{menu.Menulink}}.sql">{{menu.Menuname}}</a>
</li>
{{/each}}
</ul> I call the sell component with that query: Select 'shell' as component,
(
Select a.Value
FROM AppSettings a
where a.Name = 'AssociationShortname'
) AS title,
'Raleway' as font,
'fr' as lang,
'heart-filled' AS icon,
'/home.sql' AS link,
(
select json_object(
'menuname',
Name,
'menulink',
Link
)
FROM (
select m.Name,
m.Link,
DisplayOrder
FROM MenuSettings m
JOIN GetUserFromSession s ON m.IsAdmin = s.IsAdmin
WHERE Session = sqlpage.cookie('session')
AND m.IsActive = 1
AND m.IsAdmin = 1
UNION
SELECT Name,
Link,
DisplayOrder
FROM MenuSettings
WHERE IsActive = 1
AND IsAdmin = 0
ORDER BY DisplayOrder
)
) as menu_item; The shell component is well displayed but without any menu. I tried to send a JSON array to handlebars or to change the template but nothing worked. I didn't check the rust code. It may not be possible to achieve what I want. I don't know. Am I doing something wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
What you are trying to do is definitely possible ! Excuse me for the long answer, but I will try to make it as generally useful to others as possible. There are two points in your question:
How to pass a list as a parameter to a component ?
How to use the list from your custom component template ?If your list contains primitive values (strings, numbers)Note that you don't have to use
If your list contains objects, and you want to extract the values of the objectSELECT json_agg(json_object('firstName', first_name, 'lastName', last_name)) AS my_list FROM my_users; And when you are lost, don't forget that you can use the debug component to see exactly what data is passed to your templates. |
Beta Was this translation helpful? Give feedback.
What you are trying to do is definitely possible !
Excuse me for the long answer, but I will try to make it as generally useful to others as possible.
There are two points in your question:
How to pass a list as a parameter to a component ?
SELECT 1 AS x, 2 AS x
will pass{ "x": [1,2] }
to your template