Partials - Using Server Connect for filename

Is it possible to use a server connect value as a filename for a partial? Basically I’m trying to create a dashboard with configurable components being displayed with different partials based on the dashboard component required.

Something like :

<%- await include({{svrconnect_dashboard_components.data.qry_dashboard[$index].dashboard_type_location}}, Object.assign({}, locals)) %>

I’ve tried several formats and I can’t seem to get it to work. Any help would be appreciated.

You’re trying to access this variable at server-side rendering phase, but the variable is only created way after the page has been rendered in the browser. You can’t ask the server to include a partial from a variable it doesn’t exist at the time

You need to run such server connect at server-side instead of asking the browser to run such

Apple -

Thanks for the response and suggested article. I may not be fully understanding how the server side rendering piece would work, at least based on the examples as I won’t know the filename to load until run-time.

Basically let’s say I have 10 partials/snippets/content pages, whatever you want to call them, containing the code of each component as a catalog of components available. A user can select 4-6 of them to load and display on their dashboard based on their preferences.

I’m not entirely sure if this is possible in Wappler but seems like it should be doable somehow.

Hey,

I don’t fully understand the use-case, but I think what you want is possible

After you know the filename, is it possible you can use the Browser component to redirect the user to the current page plus a GET argument containing such value? Then, you’re able to do a partial include by looking at the $_GET variable

Note that, after you get this working, you will eventually need to use server-side rendering to filter the $_GET variable, as you may want to restrict the filenames the users may be allowed to access, otherwise this is a security issue

I slapped together a VERY crude wireframe to try to illustrate what I’m trying to accomplish.

Perhaps that will help provide a somewhat clearer picture of what I’m trying to accomplish.

perhaps rather than try to specify the partial name as a variable you could place them in a conditional regions to they are only rendered under the appropriate circumstances. Think that should work (never tried)

2 Likes

Thanks! That’s a potential option but it would still load, not display, all of the partials during rendering. I’ll play around with that for a while to see how big of an impact it may have.

Still hoping for a cleaner solution, if one exists.

If it is in a conditional region it should not load, that is the difference between using a conditional region and using to show/hide where it would be loaded then shown/hidden accordingly

Don’t you store the widget selection per user on the database?
With that info in the database you can load partials dynamically server-side.

Hmm…I tried both with show/hide and a conditional region and they act the same as far as I can tell. Both brought in the partial into the DOM even though it was never displayed.

EDIT : I was looking at the source, not DOM. So in fact the conditional might just work. Thanks!

JonL - I’m not sure this is exactly what I’m looking for unless I’m missing something here. I’m not merely trying to render a few attributes from server side but a set of full partials like a card with a chart in each. Referencing back to my poorly thrown together image, a user could have selected many partials in any order for their dashboard. Perhaps what you provided is what I need and I’m just not connecting the dots properly in my head.

See Teodors comments re rendering within conditional regions in this post (which is what I recalled when making the suggestion)

Thanks! That’s exactly where I found the errors of my ways :slight_smile: and added the EDIT to my previous comment. Appreciate all the help!

1 Like