martini-contrib / render

Martini middleware/handler for easily rendering serialized JSON, XML, and HTML template responses.
MIT License
245 stars 57 forks source link

Define sections for template parsing. #46

Closed jsgv closed 5 years ago

jsgv commented 9 years ago

I am trying to define code blocks that will get injected in the base template if they are defined. I don't want to include all the scripts that are required on one page onto another that doesn't require it.

Basically what im trying to do is something like:

on the layout: admin.tmpl:

<script src="jquery.min.js"></script>
<script src="scripts.min.js"></script>
{{ footer_extra }}

and on new.tmpl:

{{define "footer_extra"}}
  <!-- scripts just for this page -->
  <script src="script-1.js"></script>
  <script src="script-2.js"></script>
  <script src="script-3.js"></script>
{{end}}

Not sure if this is something i could just achieve with Go, kinda new to the language. Thanks!

jsgv commented 9 years ago

I noticed that I can't define more than one template, which kinda defeats what I'm trying to achieve.

index.tmpl

{{define "footer_extra"}}
  <!-- scripts just for this page -->
  <script src="script-1.js"></script>
  <script src="script-2.js"></script>
{{end}}

new.tmpl

{{define "footer_extra"}}
  <!-- scripts just for this page -->
  <script src="script-3.js"></script>
  <script src="script-4.js"></script>
{{end}}

layout.tmpl

<script src="main.js"></script>
{{template "footer_extra"}}

will throw a PANIC template: redefinition of template "footer_extra"

dariusc93 commented 9 years ago

@jesusjjf Was this ever resolved?