Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
escaping php and javascript in default page
having issues with this little bit of code
<txp:php> for ($i = 0; $i < count($items); $i++) {
echo 'imgsGallery['.$i.'] = new Object();
imgsGallery['.$i.'].image = new Image();
imgsGallery['.$i.'].image.src = "'.if(isset($items[$i]['LINK'])) echo $items[$i]['LINK'];";.'
imgsGallery['.$i.'].title = "'.if(isset($items[$i]['TITLE'])) echo str_replace("\n", '', $items[$i]['TITLE']);";.'
imgsGallery['.$i.'].caption = "'.if(isset($items[$i]['DESCRIPTION'])) echo str_replace("\n", '', $items[$i]['DESCRIPTION']);";
}
</txp:php>
I think I’ve been looking at it too much, I don’t think im escaping it properly. I keep getting this error syntax error, unexpected T_IF
any help would be much appreciated, thanks
Offline
#2 2007-01-21 07:37:21
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: escaping php and javascript in default page
Yes, JavaScript and PHP can be really evil to work with. I recommend using the ‘here document’ syntax of the echo construct:
<txp:php>
for ($i = 0; $i < count($items); $i++) {
$item_link = isset($items[$i]['LINK']) ?
$items[$i]['LINK'] : '';
$item_title = isset($items[$i]['TITLE']) ?
str_replace("\n", '', $items[$i]['TITLE']) : '';
$item_description = isset($items[$i]['DESCRIPTION']) ?
str_replace("\n", '', $items[$i]['DESCRIPTION']) : '';
echo <<<javascript
imgsGallery[$i] = new Object();
imgsGallery[$i].image = new Image();
imgsGallery[$i].image.src = '$item_link';
imgsGallery[$i].title = '$item_title';
imgsGallery[$i].caption = '$item_description';
javascript; // make sure there are no tabs or other whitespace at the start of this line
}
</txp:php>
Offline
Re: escaping php and javascript in default page
hi, thanks for the response. I’m now getting an syntax error, unexpected $end
error. thanks for your help!!
Offline
#4 2007-01-21 09:18:36
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: escaping php and javascript in default page
Hmm. Do you happen to be entering this into an article? or is it in a form/page?
Offline
Re: escaping php and javascript in default page
its going into a page
Offline
#6 2007-01-22 20:21:51
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: escaping php and javascript in default page
Thing is this works fine for me, so I recommend you verify that you’ve got the code entered properly. For instance, did you follow this instruction:
// make sure there are no tabs or other whitespace at the start of this line
Offline
#7 2007-02-03 13:09:00
- tito
- New Member
- Registered: 2007-02-03
- Posts: 4
Re: escaping php and javascript in default page
Hello everyone!
I’m newbie in textparttern, and i need a little help with two thinks.
Looks very cool, thank you : )
One very related with this post, thanks in advance
1:
I’m triyng to highlight php code and works good but with some strange modifications..
notextile. <txp:php>
highlight_string("
<?
$me = new vida(uniqid());
while($me->estoy_vivo())
{
$me->vivir();
}
$me->init_infierno();
?>
");
</txp:php>
the output is http://phpclases.com/article/2/probando-codigo-php any idea?
I will post PHP code all the time so if there is a better way give me some clues, i don’t know so much about textpartterns.
2:
¿Where is the value of the string of “comments” here http://phpclases.com/article/1/vamos-de-nuevo ?
3:
¿who to add the “Title of the section of the links” in templates?
Very thanks!
Offline
#8 2007-02-04 04:47:12
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: escaping php and javascript in default page
- FAQ: Using PHP code in Textpattern
- TextBook: comments_invite
- TextBook: Write Subtab > Comments
notextile.. <txp:php>
highlight_string('
<?
$me = new vida(uniqid());
while($me->estoy_vivo())
{
$me->vivir();
}
$me->init_infierno();
?>
');
</txp:php>
Offline
#9 2007-02-08 11:28:18
- tito
- New Member
- Registered: 2007-02-03
- Posts: 4
Re: escaping php and javascript in default page
Thank you : )
regards
Offline