⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Wt
All Projects
Wt
Overview
Activity
Roadmap
Issues
Wiki
Forums
Download (971 Bytes)
Rendering template within a template on the server-side.
» start.hpp
Plug Gulp
, 03/04/2019 12:27 AM
#if !defined(_start_hpp_)
#define _start_hpp_
#include
<memory>
#include
<sstream>
#include
<Wt/WTemplate.h>
#include
<Wt/WResource.h>
#include
<Wt/Http/Response.h>
class
start
:
public
Wt
::
WResource
{
public:
void
handleRequest
(
Wt
::
Http
::
Request
const
&
request
,
Wt
::
Http
::
Response
&
response
)
override
{
response
.
setMimeType
(
"text/html; charset=utf-8"
);
response
.
addHeader
(
"Server"
,
"TemplateWidget"
);
// Main template
Wt
::
WTemplate
t
{
Wt
::
WTemplate
::
tr
(
"start"
)};
// Inject another template into main template
#define BIND_WIDGET
#if defined(BIND_WIDGET)
// This core dumps because there is no session available
t
.
bindWidget
(
"w1"
,
std
::
make_unique
<
Wt
::
WTemplate
>
(
Wt
::
WTemplate
::
tr
(
"w1"
)));
#else
// This works
Wt
::
WTemplate
w
{
Wt
::
WTemplate
::
tr
(
"w1"
)};
std
::
stringstream
ss
;
w
.
renderTemplate
(
ss
);
t
.
bindString
(
"w1"
,
ss
.
str
());
#endif
// Send it to client
t
.
renderTemplate
(
response
.
out
());
}
};
#endif //_start_hpp_
« Previous
1
2
3
Next »
(3-3/3)
Loading...