On Wed, Nov 12, 2008 at 5:35 AM, Kornel Lesiński <[EMAIL PROTECTED]
> wrote:

> On 12-11-2008 at 10:41:35 romtek <[EMAIL PROTECTED]> wrote:
>
>  According to the manual, repeat/item/start should return *true* if item is
>> the first one. However, it returns 1 instead of true and 0 otherwise.
>>
>
> In the code it's:
>            case 'start':
>                return $this->index === 0;
>
> so it does return true. It may seem otherwise, because PHPTAL *prints* true
> as "1" and false as "0" in HTML. "true" and "false" *strings* are less
> likely to be useful representation of booleans in contexts other than inline
> Javascript.
>
> However, if you output any values in Javascript, then HTML encoding is
> inappropriate there. You *have to* use json_encode() to reliably inserting
> values in Javascript:
>
> <![CDATA[
>        var b = ${php:true} // Wrong. Gives 1
>        var b = ${structure php:json_encode(true)} // OK. Gives true
> ]]>
>
> This is especially important for strings in Javascript, which can't be
> safely escaped with just htmlspecialchars() and addslashes().
>


Thank you, Kornel. I understand now, and the additional information about
json_encode() may be useful to me in the future. But for now, I output in
HTML.

It would be good to have this explanation of how *true* and *false* are
printed by PHPTAL in HTML, in the manual. What you wrote could be added to
it almost without a change.

Roman
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to