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

go:embed Assets - load tempaltes from Assets #195

Closed
replay111 opened this issue Sep 25, 2021 · 2 comments
Closed

go:embed Assets - load tempaltes from Assets #195

replay111 opened this issue Sep 25, 2021 · 2 comments

Comments

@replay111
Copy link

Hi,

I am totally new with go, but I am trying to prepare simple web page and I want to embed tempaltes files to final binary.
My question is how to do that ;-)

I've prepared someting like:


//go:embed templates
var assets embed.FS

// and passes it to my application config:
app.TemplatesFS = assets

but I have no idea how to use it with jet templates.

I am using jet with files on file system:

var view = jet.NewSet(
	jet.NewOSFileSystemLoader("./templates"),
	jet.InDevelopmentMode(), // remove in production
)

then I have function to render:

func TemplateRender(w http.ResponseWriter, tplName string, data jet.VarMap) error {
 

	t, err := view.GetTemplate(tplName)
	if err != nil {
		log.Printf("Template not found or other error ocurred: %v", err)
		return err
	}

	err = t.Execute(w, data, nil)
	if err != nil {
		log.Printf("Error execution template: %v", err)
		return err
	}

	return nil
}

and this is working fine, but when I move compiled app to some other place I do not have access to my html files :(

Can someone show me (in a very simple code ;-) :-) ) how to do that - this would be some start for me

thanks!

@sauerbraten
Copy link
Collaborator

This is a bit of an open issue, basically you have to write an adapter between Go's fs.FS and jet's Loader interface. See #191 for more details. A workaround is to just use http.FS, which Jet already knows how to use.

I'll close this because it's basically the same feature request as #191, but feel free to reply here or reopen when the information in #191 doesn't completely solve your problem.

@replay111
Copy link
Author

Thanks for replay ;-) I have seen this issue but, as I mentioned I am starting learning go, I do not know how to pass this loader to Jet Engine ;-) But I will try to experiment with it - maybe I will find the way ;-)

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

No branches or pull requests

2 participants