Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Go Template panic can't install method/function "contentFor" with 0 results #1767

Closed
tw-maustin opened this issue Aug 16, 2019 · 7 comments
Closed
Assignees
Labels
bug Something isn't working help wanted Feel free to contribute!
Milestone

Comments

@tw-maustin
Copy link

Description

When using Go Templates Engine in a default build. there is a panic related to the "contentFor" helper.

Steps to Reproduce the Problem

Please describe in painful detail what you did (so others can play along with you) to get to this point. This includes things like the exact command(s) you used, or the curl command you used, that sort of thing.

  1. buffalo new tmpl
  2. buffalo generate action foo index
  3. rename generated file templates/foo/index.plush.html to templates/foo/index.tmpl
  4. in actions/foo.go update line to reference tmpl
    return c.Render(200, r.HTML("foo/index.tmpl"))

Expected Behavior

I expected this would render the foo/index.tmpl contents via the default go template renderer

Foo#Index

Actual Behavior

500 Error
can't install method/function "contentFor" with 0 results

In the happiest of happy places what should have happened?
Template should render.

Note

I further tracked the issue and discovered that if I remove "contentFor" from the helpers map in GoTemplateEngine delete(helpers,"contentFor") The template will then render properly. Obviously this is not a real fix, but I thought the information might help track the actual problem.

Info

-> Go: Checking installation
✓ The `go` executable was found on your system at: /usr/local/go/bin/go

-> Go: Checking minimum version requirements
✓ Your version of Go, 1.12.6, meets the minimum requirements.

-> Go: Checking GOPATH
✓ You are using Go Modules, so no need to worry about the GOPATH.

-> Go: Checking Package Management
✓ You are using Go Modules (`go`) for package management.

-> Go: Checking PATH
✓ Your PATH contains /home/maustin/projects/go/bin.

-> Node: Checking installation
✓ The `node` executable was found on your system at: /usr/local/bin/node

-> Node: Checking minimum version requirements
✓ Your version of Node, v11.12.0, meets the minimum requirements.

-> NPM: Checking installation
✓ The `npm` executable was found on your system at: /usr/local/bin/npm

-> NPM: Checking minimum version requirements
✓ Your version of NPM, 6.9.0, meets the minimum requirements.

-> Yarn: Checking installation
✓ The `yarnpkg` executable was found on your system at: /usr/local/bin/yarnpkg

-> Yarn: Checking minimum version requirements
✓ Your version of Yarn, 1.16.0, meets the minimum requirements.

-> PostgreSQL: Checking installation
✘ The `postgres` executable could not be found on your system.
For help setting up your Postgres environment please follow the instructions for you platform at:

https://www.postgresql.org/download/

-> MySQL: Checking installation
✘ The `mysql` executable could not be found on your system.
For help setting up your MySQL environment please follow the instructions for you platform at:

https://www.mysql.com/downloads/

-> SQLite3: Checking installation
✘ The `sqlite3` executable could not be found on your system.
For help setting up your SQLite3 environment please follow the instructions for you platform at:

https://www.sqlite.org/download.html

-> Cockroach: Checking installation
✘ The `cockroach` executable could not be found on your system.
For help setting up your Cockroach environment please follow the instructions for you platform at:

https://www.cockroachlabs.com/docs/stable/

-> Buffalo: Checking installation
✓ The `buffalo` executable was found on your system at: /home/maustin/projects/go/bin/buffalo

-> Buffalo: Checking minimum version requirements
✓ Your version of Buffalo, v0.14.9, meets the minimum requirements.

-> Buffalo: Application Details
Pwd         /c/devel/tmpl
Root        /c/devel/tmpl
GoPath      /home/maustin/projects/go
PackagePkg  tmpl
ActionsPkg  tmpl/actions
ModelsPkg   tmpl/models
GriftsPkg   tmpl/grifts
WithModules true
Name        tmpl
Bin         bin/tmpl
VCS         git
WithPop     true
WithSQLite  false
WithDep     false
WithWebpack true
WithNodeJs  true
WithYarn    true
WithDocker  true
WithGrifts  true
AsWeb       true
AsAPI       false
InApp       true
PackageJSON {map[]}

-> Buffalo: config/buffalo-app.toml
name = "tmpl"
bin = "bin/tmpl"
vcs = "git"
with_pop = true
with_sqlite = false
with_dep = false
with_webpack = true
with_nodejs = true
with_yarn = true
with_docker = true
with_grifts = true
as_web = true
as_api = false

-> Buffalo: config/buffalo-plugins.toml
[[plugin]]
  binary = "buffalo-pop"
  go_get = "github.com/gobuffalo/buffalo-pop"

-> Buffalo: go.mod
module tmpl

go 1.12

require (
	cloud.google.com/go v0.36.0 // indirect
	github.com/cockroachdb/apd v1.1.0 // indirect
	github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c // indirect
	github.com/gobuffalo/buffalo v0.14.9
	github.com/gobuffalo/buffalo-pop v1.16.0
	github.com/gobuffalo/envy v1.7.0
	github.com/gobuffalo/mw-csrf v0.0.0-20190129204204-25460a055517
	github.com/gobuffalo/mw-forcessl v0.0.0-20190224202501-6d1ef7ffb276
	github.com/gobuffalo/mw-i18n v0.0.0-20190224203426-337de00e4c33
	github.com/gobuffalo/mw-paramlogger v0.0.0-20190224201358-0d45762ab655
	github.com/gobuffalo/packr v1.30.1
	github.com/gobuffalo/packr/v2 v2.5.2
	github.com/gobuffalo/pop v4.11.3+incompatible
	github.com/gobuffalo/suite v2.8.1+incompatible
	github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
	github.com/jackc/pgx v3.5.0+incompatible // indirect
	github.com/markbates/grift v1.1.0
	github.com/satori/go.uuid v1.2.0 // indirect
	github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 // indirect
	github.com/stretchr/testify v1.4.0 // indirect
	github.com/unrolled/secure v1.0.1
)

@markbates
Copy link
Member

Those helpers are written for plush, and don’t support Go templates as Go’s templating system is capable of such feats of strength. If you use Go templates you won’t get any of the plush templates. This is expected behavior.

@markbates
Copy link
Member

https://gobuffalo.io/en/docs/helpers The documention states this.

@tw-maustin
Copy link
Author

The issue is not that I want to use the helpers, the issue is that I can't use go templates, because as far as I can tell by default it's attempting to inject the helpers.

t = t.Funcs(helpers)

Did I miss something in the document where I need to explicitly remove the helpers in order to use go templates?

@markbates
Copy link
Member

That is a different issue. The ticket reads the other way. I’ll reopen because it probably shouldn’t do that.

@markbates markbates reopened this Aug 16, 2019
@markbates markbates added bug Something isn't working help wanted Feel free to contribute! labels Aug 16, 2019
@markbates markbates added this to the v0.15.0 milestone Aug 16, 2019
@markbates markbates removed this from the v0.15.0 milestone Oct 30, 2019
@paganotoni paganotoni self-assigned this Apr 8, 2020
@paganotoni paganotoni modified the milestones: v0.16.3, v0.16.4 Apr 8, 2020
@paganotoni
Copy link
Member

@tw-maustin As I'm not typically using go templates with buffalo I have a question for you, do you use any of the helpers when you use Go templates or you don't ? @markbates would the solution for this one avoid passing the buffalo helpers to Go templates or just removing ContentFor ?

@tw-maustin
Copy link
Author

Honestly, I am also using plush templates now. From what I remember reading in the docs at that time, I would not have expected any of the helpers to work with Go Templates.

@paganotoni
Copy link
Member

Solved in v0.16.8

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Feel free to contribute!
Projects
None yet
Development

No branches or pull requests

3 participants