ajaxian
(Dorioajax)
December 13, 2010, 10:32am
#1
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
<body>
<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:
&lt;h1&gt;In case of no js setting, ... blablabla...&lt;/h1&gt;
Is there a way to have the Html code without this $amp;lt etc …
Thanks
mdomba
(Maurizio Domba Cerin)
December 13, 2010, 10:44am
#2
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…
ajaxian
(Dorioajax)
December 13, 2010, 10:54am
#3
Do you mean that you obtain
<h1> text ... </h1>
and not
&lt;h1&gt;In case of no js setting, ... blablabla...&lt;/h1&gt
?
Why I process like this, it is because, depending to the action, there is a specific
<noscript></noscript>
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
mdomba
(Maurizio Domba Cerin)
December 13, 2010, 11:00am
#4
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…
ajaxian
(Dorioajax)
December 13, 2010, 11:01am
#5
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 !
mdomba
(Maurizio Domba Cerin)
December 13, 2010, 11:05am
#6
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…
ajaxian
(Dorioajax)
December 13, 2010, 11:10am
#7
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
mdomba
(Maurizio Domba Cerin)
December 13, 2010, 11:17am
#8
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…
mdomba
(Maurizio Domba Cerin)
December 13, 2010, 11:27am
#9
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
ajaxian
(Dorioajax)
December 13, 2010, 11:27am
#10
I go deeper in the problem.
In my layout when I write only
<?php echo $this->noscript; ?>
with
$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 …
ajaxian
(Dorioajax)
December 13, 2010, 11:32am
#11
OK,
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 …
mdomba
(Maurizio Domba Cerin)
December 13, 2010, 11:38am
#12
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