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

iris.Jet: no view engine found for '.jet' or '.html' #1327

Closed
Dexus opened this issue Aug 5, 2019 · 4 comments
Closed

iris.Jet: no view engine found for '.jet' or '.html' #1327

Dexus opened this issue Aug 5, 2019 · 4 comments

Comments

@Dexus
Copy link

Dexus commented Aug 5, 2019

Hi @kataras,

I use the new ViewEngine for Jet, but there is a problem:

no view engine found for '.html'

I use:

tmpl := iris.Jet("./views", ".jet.html") // no view engine found for '.html'
// ....
ctx.View("pages/index.jet.html", todos)

// or

tmpl := iris.Jet("./views", ".html.jet") // no view engine found for '.jet'
// ....
ctx.View("pages/index.html.jet", todos)

In view of this the Problem is here:

iris/view/view.go

Lines 23 to 28 in eba6adb

func (v *View) Find(filename string) Engine {
extension := filepath.Ext(filename)
// Read-Only no locks needed, at serve/runtime-time the library is not supposed to add new view engines
for i, n := 0, len(v.engines); i < n; i++ {
e := v.engines[i]
if e.Ext() == extension {

Because it only takes over the last point of the expansion, but in Jet it can also be .jet, .jet.html and .html.jet, which do not match here.

Either it has to be adapted there, the jet engine should be adapted.

What are you thinking?

Regards, Josef

@kataras
Copy link
Owner

kataras commented Aug 5, 2019

Hello Josef,

I see, the problem is on filepath.Ext. You shouldn't register the jet view engine twice, an improvement will be to accept more than one extension for the same view engine (the general code you pointed out is correct as it is. It does not allow the same extension to be used in more than view engine. Unique extension(s) per view engine, two view engines can't share the same extension as the context.View uses the extension and calls the Find method to select what view engine to use to render a template file).

I will implement the http method override feature and fix that issue (which is not only on jet but in general), which is quite easy, tomorrow as I am 26 hours asleep straight already... Meanwhile you can just use the .jet : https://github.com/kataras/iris/tree/master/_examples/view/template_jet_0

@kataras kataras closed this as completed in d2e3066 Aug 5, 2019
@kataras
Copy link
Owner

kataras commented Aug 5, 2019

Actually I've just pushed a fix. go get github.com/kataras/iris@master :P I couldn't hold myself, it was so easy. Thanks @Dexus

@Dexus
Copy link
Author

Dexus commented Aug 5, 2019

Hello, Gerasimos,

thanks for the execution. At the moment I just stumbled across the behavior with the "extended" extensions. What I noticed when adapting the nunjucks template (in NodeJS comparable to Jet in Go) and the API.

I'm only using .jet for the first one now, so I'm looking forward to supporting several extensions soon.

Greetings, Josef

@kataras
Copy link
Owner

kataras commented Aug 5, 2019

Yes, now you can register any extension (with more than one dots) - still single per one view engine. No need to implement multi for a single engine yet, if requested and needed it's easy to add it too, just give me an example engine and usage and I'll do it.

github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020
Former-commit-id: db3f5014cbc5148cfbe542ec69c2ff330677363b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants