Newline being inserted after plugin

View: New views
7 Messages — Rating Filter:   Alert me  

Newline being inserted after plugin

by Josh Trutwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I created a smarty function called {link_to_template} that creates a
URL designed to go inside a <a href=""> - for example:

<a href="{link_to_template param1=xyz}">Blah</a>

This creates a cache php file with the following:

<a href="<?php echo
smarty_function_link_to_template(array('param1' =>
'xyz'), $this);?>

">Blah</a>

There is a single blank line after the ?> (not two in the code above,
I inserted one for readability).  This was never a problem under
php4 - but moving the same site to php5 I get an error now:

Fatal error: Cannot use string offset as an array in ...

I verified the actual return value in the plugin does NOT contain a
newline so it seems smarty is putting it in there.

Is there any way to prevent a plugin from automagically inserting a
carriage return after the ?> or is there something else I did?

Thanks,

Josh

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Newline being inserted after plugin

by Peggy Schatz | screen-card.design :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Josh,

I'm not sure whether this will do the trick, but I'd suggest to try the
strip modificator on the output...

Ciao Peggy


Josh Trutwin schrieb:

> I created a smarty function called {link_to_template} that creates a
> URL designed to go inside a <a href=""> - for example:
>
> <a href="{link_to_template param1=xyz}">Blah</a>
>
> This creates a cache php file with the following:
>
> <a href="<?php echo
> smarty_function_link_to_template(array('param1' =>
> 'xyz'), $this);?>
>
> ">Blah</a>
>
> There is a single blank line after the ?> (not two in the code above,
> I inserted one for readability).  This was never a problem under
> php4 - but moving the same site to php5 I get an error now:
>
> Fatal error: Cannot use string offset as an array in ...
>
> I verified the actual return value in the plugin does NOT contain a
> newline so it seems smarty is putting it in there.
>
> Is there any way to prevent a plugin from automagically inserting a
> carriage return after the ?> or is there something else I did?
>
> Thanks,
>
> Josh

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Newline being inserted after plugin

by Monte Ohrt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

A new line is created after the ?> because PHP eats the newline.

So, this (foo outputs 'FOO'):

TEST"{foo}"TEST

is compiled to:

TEST"<?php echo foo(array(), $this);?>
"TEST

(see the newline inserted)

And the final output:

TEST"FOO"TEST

(no newline)


Josh Trutwin wrote:

> I created a smarty function called {link_to_template} that creates a
> URL designed to go inside a <a href=""> - for example:
>
> <a href="{link_to_template param1=xyz}">Blah</a>
>
> This creates a cache php file with the following:
>
> <a href="<?php echo
> smarty_function_link_to_template(array('param1' =>
> 'xyz'), $this);?>
>
> ">Blah</a>
>
> There is a single blank line after the ?> (not two in the code above,
> I inserted one for readability).  This was never a problem under
> php4 - but moving the same site to php5 I get an error now:
>
> Fatal error: Cannot use string offset as an array in ...
>
> I verified the actual return value in the plugin does NOT contain a
> newline so it seems smarty is putting it in there.
>
> Is there any way to prevent a plugin from automagically inserting a
> carriage return after the ?> or is there something else I did?
>
> Thanks,
>
> Josh
>
>  

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Newline being inserted after plugin

by Josh Trutwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 10 Oct 2007 09:03:35 -0500
Monte Ohrt <monte@...> wrote:

> A new line is created after the ?> because PHP eats the newline.
>
> So, this (foo outputs 'FOO'):
>
> TEST"{foo}"TEST
>
> is compiled to:
>
> TEST"<?php echo foo(array(), $this);?>
> "TEST
>
> (see the newline inserted)
>
> And the final output:

Final output in the cache .php file or in the browser?  If this is
how it should appear in the cached php I'm not seeing this -
the .php cache has what you have above with a newline after ?>.
 
> TEST"FOO"TEST
>
> (no newline)

Thanks - but what do I do to not get a php fatal error when the
template is rendered?

Josh

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Newline being inserted after plugin

by Monte Ohrt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That error has nothing to do with the newline, it has to do with how
PHP5 handles strings and arrays. Double check which line is receiving
the error, and see if there is something being accessed as an array,
when actually no array is present.

Josh Trutwin wrote:

> I created a smarty function called {link_to_template} that creates a
> URL designed to go inside a <a href=""> - for example:
>
> <a href="{link_to_template param1=xyz}">Blah</a>
>
> This creates a cache php file with the following:
>
> <a href="<?php echo
> smarty_function_link_to_template(array('param1' =>
> 'xyz'), $this);?>
>
> ">Blah</a>
>
> There is a single blank line after the ?> (not two in the code above,
> I inserted one for readability).  This was never a problem under
> php4 - but moving the same site to php5 I get an error now:
>
> Fatal error: Cannot use string offset as an array in ...
>
> I verified the actual return value in the plugin does NOT contain a
> newline so it seems smarty is putting it in there.
>
> Is there any way to prevent a plugin from automagically inserting a
> carriage return after the ?> or is there something else I did?
>
> Thanks,
>
> Josh
>
>  

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Newline being inserted after plugin - Still stumped

by Josh Trutwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 10 Oct 2007 09:30:29 -0500
Monte Ohrt <monte@...> wrote:

> That error has nothing to do with the newline, it has to do with
> how PHP5 handles strings and arrays. Double check which line is
> receiving the error, and see if there is something being accessed
> as an array, when actually no array is present.

Monte, thanks, but I'm still having trouble finding the problem.

I have the contents of the cached .php file here:

http://intel2.intrcomm.net/smarty.phps

Search for smarty_function_pb_link_to_template - the error is on the
line after the second occurrence:

Fatal error: Cannot use string offset as an array
in /httpd/208.42.183.71/usnl.intrcomm.net/html/templates/cache/%%03^031^031BA0FD%%template-pb_nurse_list_12.php.php
on line 67

I ran this file through php -l (lint check) and it said there were no
Synax errors.  But something has to be amiss because there is another
use of the link_to_template function above this one that works just
fine.

Also might be helpful:

http://intel2.intrcomm.net/template.phps (the template)
http://intel2.intrcomm.net/function.phps (the plugin definition)

Usually problems like this aren't too hard to find, but I've looked
at it and another smarty wizard and we're both stumped.

Thanks,

Josh

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Newline being inserted after plugin - [SOLVED]

by Josh Trutwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Found the problem - it was in the {pb_get_items} function, I wasn't
correctly setting up my $items variable and the {foreach
from=$items item=nurse} loop was choking.

Thanks,

Josh

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

LightInTheBox - Buy quality products at wholesale price