Commit b6df895d authored by astaxie's avatar astaxie

add template func Substr function

parent 31f505bf
......@@ -29,6 +29,7 @@ func init() {
beegoTplFuncMap["dateformat"] = DateFormat
beegoTplFuncMap["date"] = Date
beegoTplFuncMap["compare"] = Compare
beegoTplFuncMap["substr"] = Substr
}
// MarkDown parses a string in MarkDown format and returns HTML. Used by the template parser as "markdown"
......@@ -39,6 +40,20 @@ func MarkDown(raw string) (output template.HTML) {
return
}
func Substr(s string, start, length int) string {
bt := []rune(s)
if start < 0 {
start = 0
}
var end int
if (start + length) > (len(bt) - 1) {
end = len(bt) - 1
} else {
end = start + length
}
return string(bt[start:end])
}
// DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
func DateFormat(t time.Time, layout string) (datestring string) {
datestring = t.Format(layout)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment