martini-contrib / render

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

need an other "yield" #57

Open takkuumi opened 8 years ago

takkuumi commented 8 years ago

my english is poor,sorry! I just want to do this,in layout

<html>
....
{{yield}}
.....

{{res}}
<html>

now,I have a index file named index.html.in the same dir,i have an other file name index.html.res. I want the index.html into the yield,and the index.html.res to the {{res}}

this is the dir like.

-----view
----------layout
---------------default.tmpl
----------xxx_dir
---------------xxx.html
---------------xxx.html.res
-----index.html
-----index.html.res

every res file content is different.How to do it?

I try to do it with Funcs,but i cant get the .res file path.

engine.Use(render.Renderer(render.Options{
        // Specify what path to load the templates from.
        Directory: conf.AppDir.View,
        // Specify a layout template. Layouts can call {{ yield }} to render the current template.
        Layout: "layout/default",
        // Specify extensions to load for templates.
        Extensions: []string{".tmpl", ".html"},
        // Specify helper function maps for templates to access.
        Funcs: []template.FuncMap{{
            "res":func(args ...interface{}) template.HTML {
                // here i cant get the .res path
                return template.HTML(s)
            },
        }},
        // Sets delimiters to the specified strings.
        Delims: render.Delims{"{{", "}}"},
        // Sets encoding for json and html content-types. Default is "UTF-8".
        Charset: "UTF-8",
        // Output human readable JSON
        IndentJSON: true,
    }))