My goal is to write complete HTML in backend and just print in front end with handlebars
pub async fn new_test(
// path: web::Path,
config: web::Data,
handlebars: web::Data<Handlebars<'_>>,
) -> Result<HttpResponse, actix_web::Error> {
let db = &config.database_connection;
let x2: String = HtmlPage::new()
.with_title("My Page")
.with_header(1, "Main Content:")
.with_container(
Container::new(ContainerType::Article)
.with_attributes([("id", "article1")])
.with_header_attr(2, "Hello, World", [("id", "article-head"), ("class", "header")])
.with_paragraph("This is a simple HTML demo")
)
.to_html_string();
// println!("--------------------------------{:?}", html);
let x1 = r#"
<!doctype html>
Html parser
Hello world
"#;
let html = handlebars
.render(
"sample",
&json!({"o":x1,"x2":x2}),
)
.map_err(actix_web::error::ErrorInternalServerError)?;
Ok(HttpResponse::Ok()
.content_type(ContentType::html())
.body(html))
}
using this code I'm unable to create the content I want
The output is this ---> The HTML tags are also printed .
I want HTML tags to be hidden and execute only contents
my handlebar file is
Thanks in advance
Why are you using handlebars if you're creating the entire HTML string elsewhere?
By default basically all HTML templating engines escape HTML content in values that are interpolated into the template to avoid allowing users to inject malicious HTML into your web page.
If you just create a response from the HTML string and set the content type to HTML, it should work without a template engine
1 Like
I want to use handlebars for dynamic data and send static data from actix web so
Is it possible
The handlebars language uses triple brackets for unescaped expressions
https://handlebarsjs.com/guide/#html-escaping
According to this issue the rust crate supports this too
1 Like
<div class="pagination_numbers">
<nav aria-label="Page navigation example">
<ul class="pagination">
{{#each pages_count}}
<li class="page-item "><a class="page-link" href="{{this}}">
{{#if (eq {{current_page}} this )}}
<ul class="page-item " ><button class="page-item active">xxsdasdsssx{{this}}</button></ul>
{{current_page}}
{{else}}
<button class="page-item">sss{{this}}</button>
{{/if}}
</a></li>
{{/each}}
</ul>
</nav>
Here I'm unable to use If condition for two dynamic values that is current reference and curent page number to highlight the current page number
If you have any suggestion please do let me know
system
Closed
October 26, 2023, 7:04am
6
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.