Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

PHP in new pages Rate Topic   - - - - -

 
  • scarroll
  • Junior Member
  • Members
  • Join Date: 12-May 07
  • 9 posts

Posted 13 May 2007 - 07:11 PM #1

I feel really dumb asking this... but how do I add php to a page? Specifically, I'm trying to edit the welcome.tpl so it picks a random image to show on the front page of the site. I have the world's simplest php statement to do so, but it isn't getting processed - it's just treating the php as text.


img src="graphics/<? echo rand(1,17); ?>.jpg"

Thanks,

Stuart

 
  • SWS
  • Senior Member
  • Members
  • Join Date: 30-Oct 06
  • 798 posts

Posted 13 May 2007 - 07:41 PM #2

Why not define the image name in the php files and assign the variable to the smarty template

i.e /include/customer/index.php

$random_image = rand(1,17) . ".jpg" ;
$smarty->assign('random_image, $random_image);


then in the tpl just use
<img src=$random_image>
[SIZE=3][/SIZE]

 
  • scarroll
  • Junior Member
  • Members
  • Join Date: 12-May 07
  • 9 posts

Posted 13 May 2007 - 08:11 PM #3

Hmm, ok. I added those two lines to "include/customer/index.php", trying several different places, and kept getting an error:

Parse error: parse error, unexpected T_STRING in /home/virtual/site40/fst/var/www/html/include/customer/index.php on line 42

The line number varied, depending on where in the file I put them, but same error.

 
  • bholland
  • Senior Member
  • Members
  • Join Date: 16-May 06
  • 129 posts

Posted 13 May 2007 - 09:12 PM #4

Yes, the line number would change depending where you put it :)

It's a syntax error...Post your code up and I'll take a look.

B

 
  • SWS
  • Senior Member
  • Members
  • Join Date: 30-Oct 06
  • 798 posts

Posted 13 May 2007 - 10:14 PM #5

Hmm, ok. I added those two lines to "include/customer/index.php", trying several different places, and kept getting an error:

Parse error: parse error, unexpected T_STRING in /home/virtual/site40/fst/var/www/html/include/customer/index.php on line 42

The line number varied, depending on where in the file I put them, but same error.


Above was an example and may not be formed correctly as I havnt tried it, altough this is how it should be done.

The problem is a missing ' at the end of ('random_image <--

$smarty->assign('random_image', $random_image);
[SIZE=3][/SIZE]