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

Declaring a type in the import block of an include will duplicate that type declaration when the include is used in multiple templates. #83

Open
abalbanyan opened this issue Jun 10, 2020 · 0 comments

Comments

@abalbanyan
Copy link

abalbanyan commented Jun 10, 2020

I'd like to be able to declare types in my partial files.

partial.html

<%!
  type MyPartial struct {
      Name string
  }
%>

templateA.html

<%: func TemplateA(data []string, buffer *bytes.Buffer) %>

<%+ "partial.html" %>

...

templateB.html

<%: func TemplateB(data []string, buffer *bytes.Buffer) %>

<%+ "partial.html" %>

...

The generated templates, templateB.html.go and templateA.html.go will both have the MyPartial type declaration, which will cause the MyPartial redeclared in this block golang error.

One potential solution to this issue would be to add a new syntax dedicated to type declarations. The types declared using this new syntax would only be output once.

Let me know if there's an alternative way to accomplish this that I'm missing. I'm also willing to submit a PR if fixing this issue is non-trivial to accomplish. Thank you very much!

@abalbanyan abalbanyan changed the title Declaring a type struct in the import block of a partial will duplicate that type when the partial is used in multiple places. Declaring a type struct in the import block of a partial will duplicate that type when the partial is used in multiple templates. Jun 10, 2020
@abalbanyan abalbanyan changed the title Declaring a type struct in the import block of a partial will duplicate that type when the partial is used in multiple templates. Declaring a type in the import block of an include will duplicate that type declaration when the include is used in multiple templates. Jun 10, 2020
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

1 participant