-
Notifications
You must be signed in to change notification settings - Fork 146
DynamicC Pages
Sumeet Chhetri edited this page Sep 13, 2018
·
1 revision
A Dynamic C++ page (DCP) is a hybrid HTML page that can contain C++ code interspersed in between. The resulting C++ code is compiled and built at run-time. Every DCP page can have a single header section, multiple body sections, multiple import declarations and multiple function sections.
Tags for sections
-
<DCPH>
- Header -
<DCPB>
- Body -
<DCPF>
- Function
An implicit screen
object is also provided in order to emit HTML to the resulting page from within function and body blocks. The <import>
tag is used to import another DCP page withing a given DCP page.
Example DCP page
<DCPH>
#include "string"
#include <iostream>
using namespace std;
</DCPH>
<!DOCTYPE html>
<html>
<body>
<import>anotherpage.dcp</import>
<h2>HTML Forms</h2>
<form action="/action_page.action">
First name:<br>
<DCPB>
std::string firstName = "Mickey";
screen << "<input type='text' name='firstname' value='" << firstName << "'>";
</DCPB>
<br>
Last name:<br>
<DCPB>
std::string lastName = "Mouse";
screen << "<input type='text' name='lastname' value='" << lastName << "'>";
</DCPB>
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.action".</p>
<DCPB>
screen << "This would be printed to the HTML page" << flush;
</DCPB>
<DCPB>
cout << "This would be printed to the terminal" << flush;
</DCPB>
</body>
</html>
<DCPF>
void testFunction()
{
cout << "C++ function defined within the dcp page" << flush;
}
</DCPF>
<DCPB>
testFunction();//Functions can normally be called within the dcp page
</DCPB>