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

template.ParseFiles #70

Closed
zaz600 opened this issue Dec 2, 2015 · 4 comments
Closed

template.ParseFiles #70

zaz600 opened this issue Dec 2, 2015 · 4 comments
Labels

Comments

@zaz600
Copy link

zaz600 commented Dec 2, 2015

how to use rice with template ParseFiles?
i need template inheritance

@lmas
Copy link

lmas commented Dec 29, 2015

You can't use ParseFiles as that loads files directly from the filesystem. You have to manually iterate over the templates and load them yourself. See #71 for an example that I've been using and watch out for that bug I found.

@zaz600
Copy link
Author

zaz600 commented Jan 3, 2016

i use ParseFiles to get one template from 2 or more

    post_template  = template.Must(template.ParseFiles(path.Join("templates", "layout.html"), path.Join("templates", "post.html")))
    error_template = template.Must(template.ParseFiles(path.Join("templates", "layout.html"), path.Join("templates", "error.html")))

are you doing the same in #71 ?

@lmas
Copy link

lmas commented Jan 3, 2016

My templates depends on my base.html template which would be equal to your layout.html so yes, I also create templates out of 2 or more files (with inheritance).

I guess you could do it like this:

tbox := rice.MustFindBox("templates")
post_template = template.Must(template.Parse(tbox.String("layout.html") + tbox.String("post.html")))
error_template = template.Must(template.Parse(tbox.String("layout.html") + tbox.String("error.html")))

Note that you still can't use ParseFiles with go.rice. Use Parse instead, so you can work with the strings returned from tbox.String

@zaz600
Copy link
Author

zaz600 commented Jan 3, 2016

Thank you. I will try it!

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

No branches or pull requests

3 participants