Search code examples
javascriptjqueryhtmlmojoliciousmojolicious-lite

How can I add HTML elements to stash mixed with text?


I'm adding a string with HTML <br> within it to the stash. This stash value is then used to populate a text area.

The problem is the browser converts the > and < to lt; and gt; and it displays wrong in the browser. Is there a way to stop this from happening?

$string = "line 1<br>line 2<br>line 3";
$self->stash(info => $string);
$self->render('infopage');

Solution

  • When you display text, you use this:

    <%= $var %>
    

    Or this

    %= $var
    

    This syntax will convert > to gt; and < to lt;

    You must to use this syntax if you want to to except conversation

    <%== $var %>
    

    Or this

    %== $var
    

    So, simply add symbol =, but it is not security.