Jump to content

Adding PHP to the tpl files


Guest jpmad4it

Recommended Posts

Guest jpmad4it

Hey guys,

I want to add a random Flash banner rotator to my site within the index.tpl file. The flash rotator runs using PHP at the backend. The link that calls the Flash is in the format:

<?php include("http://www.mysite.com/banners"); ?>

I have also used this in other ways such as:

<?php $file = file_get_contents("http://www.mysite/banners"); ?>

At the moment I am using a single swf file in my index.tpl file using the <object> tag, but this was just a temporary measure to align the Flash correctly. What I want is to be able to use the random Flash banner rotator which uses PHP.

Can anyone help as I am not a very proficient coder :)

regards Jp

Link to comment
Share on other sites

To answer your title query - no, it's not possible to add PHP to the template files.

However, it may be possible to include your PHP file using an image tag, as in:

<img src="http://www.mysite.com/banners">

But since you're including a flash file, this may not work either.

CubeCart uses the XTemplate system, and in this system, the PHP code assigns dynamic content to variables, which are then used to insert that content into the templates.

To add new content to the index.tpl (I'm assuming you're referring to the global index template), you'll have to add your PHP code to the index.php file and assign the output of the code to a new variable, and then add that new variable to the template file where you want it to show up.

I'm not a coder myself, so the exact details of how this is done is beyond me. But I hope that this helps to point you in the right direction.

Link to comment
Share on other sites

Guest wamasterhunter

I think I remember seeing a post on how to insert a flash banner in CC. If you check the pinned topic I think it is in there, it might help.

Micah

Link to comment
Share on other sites

Guest jpmad4it

To answer your title query - no, it's not possible to add PHP to the template files.

However, it may be possible to include your PHP file using an image tag, as in:

<img src="http://www.mysite.com/banners">

But since you're including a flash file, this may not work either.

CubeCart uses the XTemplate system, and in this system, the PHP code assigns dynamic content to variables, which are then used to insert that content into the templates.

To add new content to the index.tpl (I'm assuming you're referring to the global index template), you'll have to add your PHP code to the index.php file and assign the output of the code to a new variable, and then add that new variable to the template file where you want it to show up.

I'm not a coder myself, so the exact details of how this is done is beyond me. But I hope that this helps to point you in the right direction.

Ah ha, that makes more sense. I think you are right in what you are saying..... defining the code in index.php and outputting it to the index.tpl file. Hmmm how's that done. :blink: Damn I wish you were a coder lol!

I don't think that this would be too difficult for a coder to do (i am just assuming here it may be difficult!)

Can anyone with PHP experience help me out?

Link to comment
Share on other sites

Guest jpmad4it

I think I remember seeing a post on how to insert a flash banner in CC. If you check the pinned topic I think it is in there, it might help.

Micah

hey thanks for that but I already have the flash displaying in the header......if you read the in initial post it explains what I am looking for.......if anyone can help with the PHP coding??

Link to comment
Share on other sites

Guest oldboy

I think I remember seeing a post on how to insert a flash banner in CC. If you check the pinned topic I think it is in there, it might help.

Micah

hey thanks for that but I already have the flash displaying in the header......if you read the in initial post it explains what I am looking for.......if anyone can help with the PHP coding??

I have a similar question for a ad rotator, images no flash.

The code i need to include:

<?php

include_once("/PATH_TO_SCRIPT/ad_rotator.php");

?>

Would it be easier to include this code in the Site Documents?

i tried a previous suggestion without luck.

<img src="/PATH_TO_SCRIPT/ad_rotator.php">

So i believe we are still stuck on what AlanT already explained:

assign the output of the code to a new variable!

assign the output of the code to a new variable!

assign the output of the code to a new variable!

But how to do that is the big question ???

Link to comment
Share on other sites

Guest jpmad4it

Ok I set this up in the PHP file:

include("http://www.mysite.com/banners/index.php");

	$body->assign("FLASH_ROT",$box_content);

It passed the data correctly to the tpl file, but I cannot get it to align correctly, it just appears at the very top of the page in the web browser. It seems to ignore any CSS command i apply to it?

Any ideas?

Link to comment
Share on other sites

Guest jpmad4it

Ok I set this up in the PHP file:

include("http://www.mysite.com/banners/index.php");

	$body->assign("FLASH_ROT",$box_content);

It passed the data correctly to the tpl file, but I cannot get it to align correctly, it just appears at the very top of the page in the web browser. It seems to ignore any CSS command i apply to it?

Any ideas?

WHAY! I did it :blink:

It works!

I added this code to the index.php file:

$file = file_get_contents("http://www.mysite.com/banners");

$body->assign("FLASH_ROT", $file);

And then called it in index.tpl using {FLASH_ROT}

I'm chuffed with myself LOL

Link to comment
Share on other sites

CONGRATULATIONS!!! :sourcerer::rolly:

I wasn't sure on the exact syntax of assigning an outside PHP file to a variable, but it looks like you've figured it out. I'll have to remember this one.

Link to comment
Share on other sites

Guest oldboy

Ok I set this up in the PHP file:

include("http://www.mysite.com/banners/index.php");

	$body->assign("FLASH_ROT",$box_content);

It passed the data correctly to the tpl file, but I cannot get it to align correctly, it just appears at the very top of the page in the web browser. It seems to ignore any CSS command i apply to it?

Any ideas?

WHAY! I did it :)

It works!

I added this code to the index.php file:

$file = file_get_contents("http://www.mysite.com/banners");

$body->assign("FLASH_ROT", $file);

And then called it in index.tpl using {FLASH_ROT}

I'm chuffed with myself LOL

Cool man...

But i cant get this to work for my image rotator php script...

Any suggestions??

Link to comment
Share on other sites

Guest jpmad4it

you need to add this to index.php :

$file = file_get_contents("/PATH_TO_SCRIPT/ad_rotator.php");

$body->assign("IMAGE_ROT", $file);

You then need to add this to the styleTemplates/global/index.tpl file to call the rotator:

{IMAGE_ROT}

I think it should work

Link to comment
Share on other sites

Guest oldboy

you need to add this to index.php :

$file = file_get_contents("/PATH_TO_SCRIPT/ad_rotator.php");

$body->assign("IMAGE_ROT", $file);

You then need to add this to the styleTemplates/global/index.tpl file to call the rotator:

{IMAGE_ROT}

I think it should work

Thanks, it almost worked... this solution only rotates a link but no image

see it live here, at the bottom of the left column--> http://www.houseofdap.com/

Any idea how to get the image displayed?

Link to comment
Share on other sites

Guest oldboy

You probably have the image paths wrong, then.

The paths are right, or the link would not show up at all..

here is the code in index.php:

// START AD ROTATOR



$file = file_get_contents("http://www.houseofdap.com/ADV/ad_rotator.php");

$body->assign("IMAGE_ROT", $file);	



// END AD ROTATOR

and the code calling this variable from index.tpl:

{IMAGE_ROT}

I guess there is something wrong with the file_get_contents command, since it will display the link but not the image.

Link to comment
Share on other sites

OK, playing the devil's advocate here :w00t:

Q. Mark, what made you think it is an image path problem?

A. Because the alt text is showing (what you are calling the link) which indicates the script is WORKING and that it CANNOT FIND THE IMAGE.

Q. I don't understand how that could be, do you have any idea.

A. Yes, I think I'll actually visit your site this time to see for myself.

Q. What did you find?

A. When I right click the file and choose "Show Image" I get this error:

404 Not Found

The requested URL /img/p_m6_white_8GB_390.jpg?6241210314619c9480a53d does not exist.

Q. What does this mean?

A. It means that you have a relative path for the image in your script. Try changing image paths to an absolute path like

http://www.houseofdap.com/ADV/img/p_m6_white_8GB_390.jpg

instead of

/img/p_m6_white_8GB_390.jpg

Understandably, this may require some modding of the script.

Link to comment
Share on other sites

Guest oldboy

OK, playing the devil's advocate here :(

Q. Mark, what made you think it is an image path problem?

A. Because the alt text is showing (what you are calling the link) which indicates the script is WORKING and that it CANNOT FIND THE IMAGE.

Q. I don't understand how that could be, do you have any idea.

A. Yes, I think I'll actually visit your site this time to see for myself.

Q. What did you find?

A. When I right click the file and choose "Show Image" I get this error:

404 Not Found

The requested URL /img/p_m6_white_8GB_390.jpg?6241210314619c9480a53d does not exist.

Q. What does this mean?

A. It means that you have a relative path for the image in your script. Try changing image paths to an absolute path like

http://www.houseofdap.com/ADV/img/p_m6_white_8GB_390.jpg

instead of

/img/p_m6_white_8GB_390.jpg

Understandably, this may require some modding of the script.

Well my php progaming skills are very rusty. So i dont this i can manage to change this script to work with relative path. And i just guess that there most be a reason for the extra number after the path.

http://www.houseofdap.com/ADV/img/p_m6_whi...494619c8f8686d8

If you open the link to the php script it will rotate the images so my hope was that this could be easy included in the index.php

http://www.houseofdap.com/ADV/ad_rotator.php

So i think i will have to give up this script and start looking for something else to rotate images, any suggestions?

Link to comment
Share on other sites

If you open the link to the php script it will rotate the images so my hope was that this could be easy included in the index.php

Hi, since you are linking to this thread again, I will try to explain further: When you open the script by typing the script address into the browser, your image paths are figured from the location typed in your browser. When you call the script from index.php, the image paths have to be figured from the root of your store, because that is the location of index.php. It's that simple.

Link to comment
Share on other sites

Guest oldboy

If you open the link to the php script it will rotate the images so my hope was that this could be easy included in the index.php

Hi, since you are linking to this thread again, I will try to explain further: When you open the script by typing the script address into the browser, your image paths are figured from the location typed in your browser. When you call the script from index.php, the image paths have to be figured from the root of your store, because that is the location of index.php. It's that simple.

I understand that, and it may sound simple but i still cant get the to work from index.tpl so the problem remains.

If its to complex to get THIS script to work maybe some one can tell me how to get rotating images on the front page via index.tpl.

I would really appreciate any help, i have already spent few days trying find a solution for this.

Link to comment
Share on other sites

  • 1 month later...
Guest LoganT

I tried this and all the php in my include file printed out on the page instead of running the php. Any ideas what would cause this?

$file = file_get_contents("test.php");

$body->assign("MENU", $file);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...