Guest jpmad4it Posted March 27, 2007 Share Posted March 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
Guest Posted March 27, 2007 Share Posted March 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
Guest wamasterhunter Posted March 27, 2007 Share Posted March 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
Guest jpmad4it Posted March 27, 2007 Share Posted March 27, 2007 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. 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? Quote Link to comment Share on other sites More sharing options...
Guest jpmad4it Posted March 27, 2007 Share Posted March 27, 2007 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?? Quote Link to comment Share on other sites More sharing options...
Guest oldboy Posted March 27, 2007 Share Posted March 27, 2007 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 ??? Quote Link to comment Share on other sites More sharing options...
Guest jpmad4it Posted March 28, 2007 Share Posted March 28, 2007 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? Quote Link to comment Share on other sites More sharing options...
Guest jpmad4it Posted March 28, 2007 Share Posted March 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
Guest Posted March 28, 2007 Share Posted March 28, 2007 CONGRATULATIONS!!! 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. Quote Link to comment Share on other sites More sharing options...
Guest wamasterhunter Posted March 28, 2007 Share Posted March 28, 2007 :sourcerer: Way to go! Very nice info to know also. Micah Quote Link to comment Share on other sites More sharing options...
markscarts Posted March 28, 2007 Share Posted March 28, 2007 :sourcerer: Good work! :rolly: Quote Link to comment Share on other sites More sharing options...
Guest jpmad4it Posted March 28, 2007 Share Posted March 28, 2007 Thanks peeps :sourcerer: Quote Link to comment Share on other sites More sharing options...
Guest oldboy Posted March 30, 2007 Share Posted March 30, 2007 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?? Quote Link to comment Share on other sites More sharing options...
Guest jpmad4it Posted April 3, 2007 Share Posted April 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
Guest oldboy Posted April 4, 2007 Share Posted April 4, 2007 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? Quote Link to comment Share on other sites More sharing options...
markscarts Posted April 5, 2007 Share Posted April 5, 2007 You probably have the image paths wrong, then. Quote Link to comment Share on other sites More sharing options...
Guest oldboy Posted April 6, 2007 Share Posted April 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
markscarts Posted April 9, 2007 Share Posted April 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
Guest oldboy Posted April 16, 2007 Share Posted April 16, 2007 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? Quote Link to comment Share on other sites More sharing options...
markscarts Posted April 23, 2007 Share Posted April 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
Guest oldboy Posted April 23, 2007 Share Posted April 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
Guest LoganT Posted May 25, 2007 Share Posted May 25, 2007 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.