Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality for dynamic includes #93 #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add functionality for dynamic includes #93 #156

wants to merge 1 commit into from

Conversation

jasper-lyons
Copy link

As per the issue raise #93 and with some amendments to corrects the suggest fix. Variables can now be used with includes so that the contents of the variable is evaluated to a string and then the include statement is evaluated as normal with the value of the string as the file name (without extension or path) to search for.

@phplego
Copy link

phplego commented Jun 25, 2014

+1 Why this very old issue still has not solved by this solution?
And, yes, this pull request has an issue. Variable "path" is declared twice. You need just to remove "var" keyword inside the "if" statement

@tj
Copy link
Owner

tj commented Jun 25, 2014

you'd have to pass it via options? seems a little weird, unless I'm misreading that, but it's not that simple, need caching etc, I haven't seen a good solid solution yet that's why there's no merge

@Vadorequest
Copy link

The var path isn't declared twice, only once since the code goes either in the if or else statement. That's not an issue. To make things look better we also could declare the var path; before the if statement.

Edit: Seems like I'm wrong:

This would be because of javascript variables all being hoisted to the top of the scope and, as an if statement doesn't create a new scope, it is in fact defined twice.

@jjackoway
Copy link

Is there a reason this can't be as simple as changing
var path = resolveInclude(name, filename);
to
var path = resolveInclude(options[name] ? options[name] : name, filename);
and leave off the options change? Am I missing something obvious?

@nikmartin
Copy link

so, without this merge or one like it, is there a way to get dynamic include paths in ejs? I need to do includes based on a portion of the path being dynamic, and have wired ejs DEEP into my app's architecture.

@mde
Copy link
Collaborator

mde commented Dec 30, 2014

I'd be happy to merge this PR or one like it if it doesn't break existing tests. I'm taking a look at it now, buit the merge might go faster if the authors of the PR get tests passing before submitting it.

Replaced path with templatePath as that is more semmantic and
lifted the templatePath definition out of the if statement so as to
prvent future jshint errors.
@jasper-lyons
Copy link
Author

@mde I've fixed this PR so that existing test pass while still providing the required functionality. If there are any other changes you'd like me to make, just let me know. :)

@mde
Copy link
Collaborator

mde commented Dec 31, 2014

@jasper-lyons I'm probably missing something, but I'm not clear on what that block of code with the switch is for in this last commit.

I made a simpler change yesterday in the master branch which passes all the tests, and added a test for the variable-based include. Can you take a look at it and see if it handles what you'd say the uses-cases are for this?

@mde
Copy link
Collaborator

mde commented Dec 31, 2014

@jasper-lyons Ah, I was looking at the changes to the built file. Looks like your change is pretty much what I implemented in master. Can you verify if it works for you?

@jasper-lyons
Copy link
Author

I can verify that it does and passes all test for me.

I added a simple test case here at line 304-308 with some fixtures, simply outlining an automated test for the use-case.

I would be happy to work on future extensions to this functionality if required.

@mde
Copy link
Collaborator

mde commented Jan 2, 2015

@jasper-lyons, I am doing a version 2.0 (using my preexisting EJS implementation from Geddy and previous) that handles includes as a simple function call at runtime: https://github.com/mde/ejs Could you take a look at it and let me know if it works for you? I believe I've gotten parity with all the existing functionality -- except filters, which I'd really like to deprecate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants