Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to render variable as html in .mako?

By
Antanas
on 11/18/13, 9:27 AM 1,658 views

Hello,

If i have a ${variable}, how can I make it render as html?

For example ${variable} contains:

<p>Foo</p>

Then placing it in .mako like so:

<div>
    ${variable}
</div>

Wolud produce:

<div>
    <p>Foo</p>
</div>

Which would be rendered in report as html, and not displayed as text in the rendered pdf.

How can this be achieved?

1

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 11/18/13, 11:17 AM

You have to replace tags:

replace < by &lt; 
    and > by &gt;
1
Jaakko Komulainen
On 11/18/13, 10:23 AM

I'm not completely sure which result you are after (if neither) but you can do like this in the .mako file:

 <%
    variable = "<p>Foo</p>"
    variable2 = since this editor likes to mess with my html tags the variable2 is in pastebin here: pastebin.com/d9gbdXCb
 %>
<div>${variable}</div>    // results in: Foo

<div>${variable2}</div>  // results in: <p>Foo</p>

My intention is to place an html element which would contain style data, f.e. <p style="this: that;"></p> and etcetera. For that purpose it needs to be rendered into html entirely, not only its contents. Your example variable2 looks promising...

Antanas
on 11/18/13, 10:28 AM

Ok, in that case can't you just do as: <% variable = "<p style='color:red'> Foo </p>" %>

Jaakko Komulainen
on 11/18/13, 10:41 AM

Don't you want to use <pre> and </pre> to preserve html content ?

Gregoire Huet
on 11/18/13, 2:24 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 11/18/13, 9:27 AM
Seen: 1658 times
Last updated: 3/16/15, 8:10 AM