You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this works fine for me. But I want this condition in a partial and I want to pass allowed roles and enabled_property to it. So I created a partial and included it in the main.ejs file but it showed the error that view_condition is not defined.
I tried using both tags but it did not work for me <%- include('./partials/view_condition') %> and <% include('./partials/view_condition') %>.
I know the path is correct because when I use a h1 tag in view_condition.ejs it renders properly
main.ejs file (that is not working)
<%- include('./apartials/view_condition',{allowed_roles : ['crew','client'],enabled_property : 'call_in_enabled'}) %>
<% if (view_condition) { %>
<!-- application code-->
<% } else{ %>
<div style="position: absolute;width: 100%;top: 50vh;display: flex;justify-content: center;">
<h1> you are not authorized to view this page</h1>
</div>
<% } %>
view_condition.ejs file (I tried using both let and var to declare varible)
If you want to pass it with all the other variables, I think you might have issues with scoping those variables because they're defined as part of the partial. It may be worth trying to define them outside of the partial if it's possible. Functionally the same should work if you pass it alongside your object as include's second argument but this might not be your preference.
I would say though, you're passing the whole list of local variables each time using that method. I think that could eventually impact performance.
I am building a website and want to conditionally render a given page. For that I have created this condition
this works fine for me. But I want this condition in a partial and I want to pass
allowed roles
andenabled_property
to it. So I created a partial and included it in the main.ejs file but it showed the error thatview_condition
is not defined.I tried using both tags but it did not work for me
<%- include('./partials/view_condition') %>
and<% include('./partials/view_condition') %>
.I know the path is correct because when I use a
h1
tag in view_condition.ejs it renders properlymain.ejs file (that is not working)
view_condition.ejs file (I tried using both let and var to declare varible)
main.ejs file (that is working)
The text was updated successfully, but these errors were encountered: