Welcome Guest, Not a member yet? Register   Sign In
Can not print style attributes
#1

[eluser]Andreas Krohn[/eluser]
In an app I am building I want to print a tag cloud, where the size of each tag is defined by the CSS font-size on the link tag, for example:
<a href="..." style="font-size: 10px">...</a>.

The html for the tag cloud (ie all the a tags) is generated in a controller and then I just print it in the view. All the tags print correctly, but for some reason the style attributes on the a tags are all empty, ie it comes out:
<a href"..." style="">...</a>

Trying to debug this I have added an extra print statement from within the controller, just to check that the right tag cloud HTML is assembled there. To my suprise this string contains the correct style attributes, _and_ when I do this the tag cloud in my view comes out perfect, with style attribues and all. For me this seems to be either a caching thing or some nifty CI security feature that I dont know about. If anybody have any ideas of how I can get my style attributes to print correctly I would really appreciate the help!

/Andreas
#2

[eluser]GSV Sleeper Service[/eluser]
can you post an example of your controller and view?
#3

[eluser]Andreas Krohn[/eluser]
After some further debugging it boils down to if I am using a doctype or not, which is quite weird. From my controller I send the $tagcloud array that contains $tags, each one with the attributes "font_size", "tag_name" and "tag_url". The view I am using looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
<h2>Tag Cloud</h2>
&lt;?php
foreach($tagcloud as $tag)
print"<a href='#' style='font-size: ".$tag->font_size."'>".$tag->tag_name."</a> ";
?&gt;
&lt;/body&gt;
&lt;/html&gt;

The tag cloud HTML rendered by this view looks like this:
<a href="#" style="">Tag10</a> <a href="#" style="">Tag15</a> <a href="#" style="">Tag20</a>

However, when removing the doctype from the view I get this HTML rendered:
<a href="#" style="font-size: 10px;">Tag10</a> <a href="#" style="font-size: 15px;">Tag15</a> <a href="#" style="font-size: 20px;">Tag20</a>

That means that when I use a doctype the style attributes are somehow emptied! I have tried this in a number of browsers and with several different valid doctypes, but the result is the same. Using CodeIgniter 1.6.1
#4

[eluser]GSV Sleeper Service[/eluser]
very odd, I've got a feeling it may be something to do with the mix of quotes in your view.
can you try this and see what happens.
Code:
&lt;?php
foreach($tagcloud as $tag):
?&gt;
<a href="#" style="font-size:&lt;?=$tag->font_size?&gt;">&lt;?=$tag->tag_name?&gt;</a>
&lt;?php
end foreach;
?&gt;
#5

[eluser]Andreas Krohn[/eluser]
Thank you very much, that works. Of course it just works in my example and not in my real app, but I am sure that is because I am mixing quotes somewhere else in that view.

But I do not really understand how the mix of quotes together with a doctype can result in CI stripping out my style attributes. Very weird!
#6

[eluser]Andreas Krohn[/eluser]
UPDATE: It just worked because my DOCTYPE also had a mixed set of quotes, I had this invalid and the tagcloud styles come out:
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd">

If I change to this correct DOCTYPE with valid quotations not styles come out:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

This is driving me mad, so any help to keep my sanity would be greatly appreciated. Today quotations and doctypes dont seem to play nicely...




Theme © iAndrew 2016 - Forum software by © MyBB