Using this for several pages. This example is a page for displaying users and CRUD.
Index page displays the user table and includes partials (modal, header).
modal.ejs has it’s own include which is the form to be rendered.
Both these partials are passed data on page load.
Header.ejs/Modal.ejs data. Works as intended. <%- await include('/settings/partials/header', Object.assign({title: "Users",btnText: "Add User"}, locals)) %>
‘/settings/users/partials/userForm’ with a variable that allows me to use any form. <%=formPath %> holds that value but page breaks.
“/api/v1/user/create” with a variable to insert the api/sc call
Have tried with various methods resulting in either breaking the page or “breaking” the variable.value
Maybe it could be fixed with the correct escaping etc.
What is the formatting to insert {{variable}} or <%= variable =%> into the include strings without breaking the page ?
That piece of code is evaluated on the server before rendering on the browser. App connect is not available for you so handlebars evaluation will not work.
It can also hold the path if passet through <%- await include('/partials/modal', Object.assign({formPath:"/settings/users/partials/userForm"}, locals)) %>
But if i try to put that in the include the page will not even save
That is a very useful Mini Tutorial on routing & using dynamic data to update page views while also leaving nothing to chance by specifying the JS and CSS files to use specifially for that view.
I'm not sure why you guys are doing so difficult as data bindings in partials as parameters are already available. So there is no need to hand code this.
It works just like the rest of the Server Side Data Bindings in NodeJS:
So you just:
Define a input data for your partial by using "Define Template Data" on its root node:
To be honest I feel that getting data from the route is quicker and simpler for this use case. Where your route will define extra params specific to that route and not to other.
However it’s a shame this is not supported from the UI.
I would like to replace :
‘/settings/users/partials/userForm’ with a variable that allows me to use any form. <%=formPath %> holds that value but page breaks.
If the form can change dynamically he will have to create a specific Server Connect just to identify which form he needs to pass. On the contrary if he sets this info directly in the route it will save him a lot of time.