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
31f505bf
Commit
31f505bf
authored
Mar 14, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add RenderBytes function
parent
281747ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
3 deletions
+23
-3
controller.go
controller.go
+23
-3
No files found.
controller.go
View file @
31f505bf
...
...
@@ -83,6 +83,20 @@ func (c *Controller) Options() {
}
func
(
c
*
Controller
)
Render
()
error
{
rb
,
err
:=
c
.
RenderBytes
()
if
err
!=
nil
{
return
err
}
else
{
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
rb
)),
true
)
c
.
Ctx
.
ContentType
(
"text/html"
)
c
.
Ctx
.
ResponseWriter
.
Write
(
rb
)
return
nil
}
return
nil
}
func
(
c
*
Controller
)
RenderBytes
()
([]
byte
,
error
)
{
//if the controller has set layout, then first get the tplname's content set the content to the layout
if
c
.
Layout
!=
""
{
if
c
.
TplNames
==
""
{
...
...
@@ -95,22 +109,28 @@ func (c *Controller) Render() error {
tplcontent
,
_
:=
ioutil
.
ReadAll
(
newbytes
)
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
string
(
tplcontent
))
_
,
file
=
path
.
Split
(
c
.
Layout
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
c
.
Ctx
.
ResponseWriter
,
file
,
c
.
Data
)
ibytes
:=
bytes
.
NewBufferString
(
""
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
}
else
{
if
c
.
TplNames
==
""
{
c
.
TplNames
=
c
.
ChildName
+
"/"
+
c
.
Ctx
.
Request
.
Method
+
"."
+
c
.
TplExt
}
_
,
file
:=
path
.
Split
(
c
.
TplNames
)
subdir
:=
path
.
Dir
(
c
.
TplNames
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
c
.
Ctx
.
ResponseWriter
,
file
,
c
.
Data
)
ibytes
:=
bytes
.
NewBufferString
(
""
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
}
return
nil
return
[]
byte
{},
nil
}
func
(
c
*
Controller
)
Redirect
(
url
string
,
code
int
)
{
...
...
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