View previous topic :: View next topic |
Author |
Message |
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 2:54 pm Post subject: Smarty and <?xml |
|
|
I just gave Smarty3 (r3014) a spin and noticed a few inconsistencies with Smarty 2.
A statement like this is just passes through the Smarty 3 parser
Code: | <?xml version="1.0" encoding="UTF-8" ?>
|
While Smarty2 will parse it like:
Code: | <?php echo '<?xml'; ?>
version="1.0" encoding="UTF-8"
<?php echo '?>'; ?>
|
Is this the desired behavior, and if so, how can one replicate Smarty 2's behavior? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Mar 04, 2009 3:14 pm Post subject: |
|
|
Smarty 3 compiles it into
Code: | <?php echo '<?xml version="1.0" encoding="UTF-8" ?>';?> |
So what's wrong with that? |
|
Back to top |
|
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 3:26 pm Post subject: |
|
|
Nothing wrong with that, but thats not what i get.
Let me show you the output of the template file as an illustration.
This is the output smarty gives me:
Code: | <?php /* Smarty version Smarty3Alpha, created on 2009-03-01 15:25:01
compiled from "./templates/includes/top.template" */ ?>
<?php if ($_smarty_tpl->getVariable('pageData')->value->mime!='text/html'): ?>
<?xml version="1.0" encoding="UTF-8"?>
<?php endif;?>
|
And that in turn produces the following PHP error:
Code: | Parse error: syntax error, unexpected T_STRING in /var/www/uonet/templates_c/2de955c712960e2cb26735b49527c588.top.template.php on line 4 |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Mar 04, 2009 3:35 pm Post subject: |
|
|
Okay, I found a problem in the parser.
I will let you know when the fix is in the SVN. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Mar 04, 2009 3:53 pm Post subject: |
|
|
The SVN has been updated with a fix. |
|
Back to top |
|
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 4:00 pm Post subject: |
|
|
The fix only does half the work, after the fix it now outputs:
Code: | <?xml version="1.0" encoding="UTF-8"<?php echo '?>';?> |
Since the beginning of the XML tag isn't escaped the same error still occurs.
This needs one more look |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Mar 04, 2009 4:15 pm Post subject: |
|
|
Can you try again? |
|
Back to top |
|
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 4:18 pm Post subject: |
|
|
Updated repository and tried again, but this time theres no change at all.
Still same output as last time. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Mar 04, 2009 4:26 pm Post subject: |
|
|
Strange.
Code: | <?xml version="1.0" encoding="UTF-8"?> |
compiles on my place to
Code: | <?php echo '<?xml';?> version="1.0" encoding="UTF-8"<?php echo '?>';?> |
Did you set force_compile or delete the old compiled template? |
|
Back to top |
|
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 4:36 pm Post subject: |
|
|
After some more exhaustive testing I came to the conclusion that this problem does not occur unless the <?xml statement in enclosed by a if-statement.
So, just having a template with the following works:
Code: | <?xml version="1.0" encoding="UTF-8"?> |
While this does not:
Code: | {if $foo}
<?xml version="1.0" encoding="UTF-8"?>
{/if}
|
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Mar 04, 2009 5:00 pm Post subject: |
|
|
I think i finally found it.
Please try once again. |
|
Back to top |
|
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 5:11 pm Post subject: |
|
|
I think you got it this time, it gives me the correct output.
Theres only one difference now when having the xml declaration inside a if statement, and that is that it forces a newline before the xml statement, and this is not allowed according to the XHTML standards.
This is the output I get:
Code: | <?php echo '
<?xml';?> version="1.0" encoding="UTF-8"<?php echo '?>';?>
|
Nice and properly escaped, just the damned newline that shouldn't be there.
Now I think Smarty 2 had the same behavior which I circumvented by writing the code like this:
Code: | {if $foo
}<?xml ... ?>{
/if}
|
That is, however now allowed in Smarty 3, so could you remove the output of the newline? |
|
Back to top |
|
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 5:15 pm Post subject: |
|
|
The newline should instead be after the XML statement.
This would be correct in this case:
Code: | ?php echo '<?xml';?> version="1.0" encoding="UTF-8"<?php echo '?>
';?>
|
That should be the anticipated output and makes the DOCTYPE begin on a line of its own. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Mar 04, 2009 5:23 pm Post subject: |
|
|
I don't think it's a bug. When you do this:
Code: | {if ...}
<?xml ... ?>
{/if} |
The newline is coming from the template, because you have a newline after the {if} tag. The template is behaving exactly as you have it. You can get around this problem by removing the newline:
Code: | {if ...}<?xml ... ?>{/if} |
Or use {strip} tags to remove whitespace. Or, trim() the template output. |
|
Back to top |
|
robert Smarty Rookie
Joined: 04 Mar 2009 Posts: 13
|
Posted: Wed Mar 04, 2009 5:42 pm Post subject: |
|
|
Ah, I see.
Thanks for the fast reply, and I hope next time I might be able to help out a bit more and supply a patch or two |
|
Back to top |
|
|