Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
b6df895d
authored
2013-03-14 21:47:39 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add template func Substr function
1 parent
31f505bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
template.go
template.go
View file @
b6df895
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment