Extensionless views fail #193

Merged
merged 1 commit into from Oct 11, 2013

Conversation

Projects
None yet
1 participant
@daffl
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Oct 11, 2013

Contributor

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.

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

1 check passed

default The Travis CI build passed
Details

@daffl daffl deleted the extensionless-views-193 branch Oct 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment