Solved

Empty span output problem with PHP + Joomla

Posted on 2010-09-18
7
705 Views
Last Modified: 2013-11-19
I am working on a custom template for Joomla but am having a problem with menu items. When a separator is created it has an invalid empty 'span' element
<span />

Open in new window

. How can I force the output of this to
<span></span>

Open in new window

?

This is causing the entire page to break in all versions of IE.

All I am doing is calling the following function:
modMainMenuHelper::render($params);

Open in new window

0
Comment
Question by:numberkruncher
  • 4
  • 2
7 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 33710917
That span element is perfectly valid XHTML.  Are you using doctype STRICT?

See this note - It is a problem with IE, not with the XHTML:
http://www.thismuchiknow.co.uk/?p=184

So thanks again, Microsoft.

If you find the render method, you might be able to add this line of code.  Adjust the variable name from $html to whatever is used to render the output string.

HTH, ~Ray
$html = str_replace('<span />', '<span></span>', $html);

Open in new window

0
 
LVL 13

Author Comment

by:numberkruncher
ID: 33710937
> Are you using doctype STRICT?

I am using the XHTML1 transitional doctype, but I did try strict to see if it made any differences...unfortunately it didn't.

> So thanks again, Microsoft.

Tell me about it!

> If you find the render method, you might be able to add this line of code...

Yes, looks like that will have to be the solution. Unfortunately the render method also inserts
  • . I was hoping that I had missed a switch or something in PHP which would revert to IE-safe code.

    The thing that I do not understand is, when I switch to the HTML4-strict doctype, the PHP script still outputs self-closing span tags... This isn't right is it?
    0
     
    LVL 13

    Author Comment

    by:numberkruncher
    ID: 33710940
    Yes, looks like that will have to be the solution. Unfortunately the render method also inserts <li />. I was hoping that I had missed a switch or something in PHP which would revert to IE-safe code.
    0
    Free Tool: Subnet Calculator

    The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

    One of a set of tools we're offering as a way of saying thank you for being a part of the community.

     
    LVL 109

    Expert Comment

    by:Ray Paseur
    ID: 33710966
    I'm not aware of any such switch, but leave the question open and maybe a Joomla expert will have a magic wand for this situation.

    You can, of course, do the same kind of str_replace() with the LI tag and any others that are mishandled by the Microsoft browsers.
    0
     
    LVL 42

    Expert Comment

    by:David S.
    ID: 33712630
    Could you avoid having the empty list-items (<li>)? They're not really semantically correct anyway.

    Sometimes I can just add styles (e.g. a background image) to the list itself. Other times I end up adding an additional wrapper <div> around a list in order to be able to move empty <li>s.
    0
     
    LVL 13

    Author Comment

    by:numberkruncher
    ID: 33712670
    The menu item is defined using the Joomla UI. The XHTML is generated by "modMainMenuHelper::render".

    Everything except the templates are entirely Joomla.
    0
     
    LVL 13

    Author Closing Comment

    by:numberkruncher
    ID: 33794745
    Thanks, sorry for the late response.
    0

    Featured Post

    Free Tool: Subnet Calculator

    The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

    One of a set of tools we're offering as a way of saying thank you for being a part of the community.

    Question has a verified solution.

    If you are experiencing a similar issue, please ask a related question

    Suggested Solutions

    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    The viewer will learn how to dynamically set the form action using jQuery.

    830 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question