I'm trying to do something rather simple -at least it should be. That was without counting that I work with EJS...
I'm completely lost. The debug messages are bullshit, the code compiles, I change it, it doesn't, I rollback, it doesn't. I restart it does, I refresh, it doesn't. What I am suppose to say?
Debug messages are obviously wrong. Once telling me the partial cannot be found, but if I fix something in the partial (or refresh, or restart, or pray) it finds it.
So, let's talk about what I'm trying to do.
I have a JSON object in a file, the file is loaded by the controller and sent to the view.
[
{
"_href": "/",
"_controller": "home",
"_action": "index",
"_icon": "home",
"_text": "Home",
"_classes": ""
},
[
{
"_href": "/",
"_controller": "sentences",
"_action": "index",
"_icon": "list",
"_text": "Sentences",
"_classes": ""
},
{
"_href": "/",
"_controller": "sentences",
"_action": "index",
"_icon": "plus",
"_text": "Sentences",
"_classes": ""
}
]
]
The aim is to generate a menu dynamically.
Now, in my view: leftNavigation.ejs
<% _.each(leftNavigation, function(entry){%>
<%- partial('../../../assets/linker/templates/leftNavigationLink', entry)%>
<%})%>
This worked, then it didn't, then it did.
The partial code: leftNavigationLink.ejs
<li>
<a href="<%= _href%>" class="part <%= _classes%> <%= __view.activePage(_controller, _action, controller, action)%>">
<i class="fa fa-<%= _icon%>"></i>
<span><%= _text%></span>
</a>
</li>
This should be easy, right? Simply loop on my array and render partials
I also tried this:
<%- partial('../../../assets/linker/templates/leftNavigationLink', leftNavigation[0])%>
It works, sometimes. Sometimes when I restart the server then the path is wrong and it cannot find the view. I don't get why or how the path could change between two server instance...
I'm sure now that sometimes the path starting by ../../../
works and sometimes doesn't. Sometimes the right path is ../../
. I don't have any clue why, the files location don't change, I just change the source code.
I'm gonna try to put all files in the same folder or I'm gonna rest my brain. If anyone have a working example of use of partials with ejs/ejs-locals and data/loop, it would be greatly appreciated.
I don't know how such bad programming tools can become that famous, I'm maybe tough but I would have done that in 5 min in PHP/Ruby. A real debugger that shows the exact error would help a lot (instead of a random file/line like what I get now)
Edit: Well, this is likely a ejs-locals issue, I've posted on the Git repo but it's not maintained anymore. (<3)
If anyone knows how I could override the partial
function, I could maybe force to look from a specific directory of my application and avoid killing myself. Maybe you'll have a better idea/fix.