Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
HtmlTemplateView.h
Go to the documentation of this file.
1
14 #pragma once
16 #include <string>
17 #include "http/HttpRequest.h"
18 #include "http/HttpResponse.h"
19
20 enum class TemplateSource {
21 Inline,
23 };
24
26 public:
27 HtmlTemplateView(const std::string& source, TemplateSource mode = TemplateSource::Inline);
28
29 std::string render(const std::map<std::string, std::string>& context = {}) const override;
30
31 void render(HttpRequest& req, HttpResponse& res) {
32 res.setContentType("text/html");
33 res.send(render());
34 }
35
36 std::string getContentType() const override;
37
38 private:
39 std::string templateSource_; // Used if mode == Inline
40 std::string filePath_; // Used if mode == FromFile
42 };
43
Abstract base class for all views in the PicoFramework.
TemplateSource
Defines the HttpRequest class for handling HTTP requests: headers, method, path, query string,...
HTTP HttpResponse class for managing status, headers, body, and streaming support.
std::string getContentType() const override
Return the MIME content type for this view.
TemplateSource mode_
std::string filePath_
std::string templateSource_
void render(HttpRequest &req, HttpResponse &res)
std::string render(const std::map< std::string, std::string > &context={}) const override
Render the view body.
Forward declaration for potential routing needs.
Definition HttpRequest.h:32
Represents an HTTP response object.
HttpResponse & setContentType(const std::string &content_type)
Set the Content-Type header.
void send(const std::string &body)
Send a full response including headers and body.