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

Extensionless views fail #193

Merged
merged 1 commit into from
Oct 11, 2013
Merged

Extensionless views fail #193

merged 1 commit into from
Oct 11, 2013

Conversation

daffl
Copy link
Contributor

@daffl daffl commented Oct 11, 2013

Sometimes I read views from my ASP.NET MVC app to get server-side processing done to the view before serving (ie., adding validations, partial views, etc). Many server-side apps provide extensionless URL's even to html pages, such as /Products/Detail.

Since there is no extension, CanJS doesn't know what render engine to use. So I am stuck with doing this workaround:

        //SET CANJS VIEW EXTENSION TO NOTHING FOR MVC ROUTES
        can.view.ext = '';

        //CHOOSE DEFAULT TEMPLATE ENGINE FOR EXTENSIONLESS VIEWS
        can.view.types[''] = can.view.types['.ejs'];

I believe the render engine should not be so coupled to the file extension, instead please give the option in view.js to specify a default render engine if not found. I think this can be done in registerView on line 411. I hope this makes sense but will glad to clarify further if needed. Thanks!

@daffl
Copy link
Contributor

daffl commented Oct 11, 2013

This has been kicking for a while but I finally attached a pull request that allows to enforce the use of a certain view engine by passing an object with a url and engine property to can.view like this:

can.view({
  url: path,
  engine: 'mustache'
}, { message: 'Hi test' });

It doesn't break backwards compatibility and allows using a specific view engine for any URL.

daffl added a commit that referenced this pull request Oct 11, 2013
@daffl daffl merged commit 988ca2a into master Oct 11, 2013
@daffl daffl deleted the extensionless-views-193 branch October 11, 2013 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant