Html encode

Hi all,

In my controller I have to set a litle Html text and I would like to give it to the view.

I set as attribut to the SiteController :

$noscript ='';

Then In my controller’s actions, I define what should be the noscript class attribute and I pass it to the render.

$this->noscript='<h1>In case of no js setting, ... blablabla...</h1>';

And in my Layout


<noscript><?php echo $this->noscript; ?></noscript>

I would expect having <h1>In case of no js setting, … blablabla…</h1> in my view, but I obtain something like:

&amp;lt;h1&amp;gt;In case of no js setting, ... blablabla...&amp;lt;/h1&amp;gt;

Is there a way to have the Html code without this $amp;lt etc …


I tryed your idea… and it works for me… seems that somewhere you encode the $noscript variable…

Anyway it’s a bad idea to set any HTML code in the controller or model… why not set just the message in the variable… and leave the code for the layout…

Do you mean that you obtain

<h1> text ... </h1>

and not

&amp;lt;h1&amp;gt;In case of no js setting, ... blablabla...&amp;lt;/h1&amp;gt


Why I process like this, it is because, depending to the action, there is a specific


tag to generate in order to give an alternative text in case javascript is not working (blocked)

And this text depends of the page you are on. I can’t fix it inside layout with “static” text.

And I do not know how to handle this without doing as I described in the previous post

Yes I’m getting plain HTML… tryed on new yiic generated code…

If you need only different text… than you can set $this->noscript="only text";

and in the layout

<noscript><h1><?php echo $this->noscript; ?></h1></noscript>

if you need text with a header you can use two variables like $noscripttitle and $noscripttext…

Be carefull.

It works also for me when I set <?php echo $this->noscript; ?> in a view but when I place the code in the layout, then It doesn’t work !

what you mean with layout?

I tryed in the view… in the column2.php and in the main.php… all three places echoes plain HTML without encoding…

In protected/views/layouts/main.php

So I don’t understand… Maybe I have a problem with my editor …

But anyway I never explicitly encode the html text with CHtml::encode function

I just noticed that you wrote “and I pass it to the render” in the first post… You don’t need to pass the variable…

I you still get the encoded text… try to create a new yii application (yiic webapp newapp)… and make only these changes… to check that you get the value non encoded…

I tryed with Yii 1.1.5

I go deeper in the problem.

In my layout when I write only

<?php echo $this->noscript; ?>


$noscript ='<h1>blablabla</h1><p>another blablabla</p>';

Then display is in Html,exactly that I expected.

BUT when I try to set this html inside a <noscript> tag(

<body><noscript><?php echo $this->noscript; ?></noscript> ....

), then It becomes not pure Html display.

Remark: When i set the message

<body><div><?php echo $this->noscript; ?></div> ....

then pure Html is displayed.

It seems it comes from the use of the <noscript> </noscript> tag …


Sorry I’m a real donkey.

All works fine.

I just use debug with firebug, and then you see pure html but encoded html between <noscript> tags …

Really sorry, to have wasted your precious time …

Anyway I already tried before answering the first time with and without the <noscript>… both cases works the same… would be very strange otherwise…

Glad you found what was wrong :)