Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
b6df895d
Commit
b6df895d
authored
Mar 14, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add template func Substr function
parent
31f505bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
template.go
template.go
+15
-0
No files found.
template.go
View file @
b6df895d
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment