Jump to content

Including a PHP file in a sidebar box.


Guest Jon Bartus

Recommended Posts

Guest Jon Bartus

Hi all,

Not positive this belongs here but I figured this was my best shot.

My client wants me to add a poll to the sidebar on his site and being naturally lazy I decided to use Fpoll for this purpose. My issue mainly lies in getting the poll file to include into the sidebar. I am adding the box by directly modifying index.tpl (If anyone wants to explain how I can make it use its own box template file they are hereby entitled to my firstborn son.) but while I can get the include to seemingly work it is resisting showing the poll itself. Here is the relevant information:

Store location: http://www.rackemtees.com/store/

Poll location: http://www.rackemtees.com/store/Fpoll/poll.php

Include Code:

					   <div class="boxTitleLeft" align="center"><img src="http://rackemtees.com/store/skins/Rack_Em/styleImages/pollhead.png" height="19" width="156" /></div>

			<div class="boxContentRight">

				<?php include("../Fpoll/poll.php"); ?>

			</div>

Any help is greatly appreciated.

Regards,

Jon

Link to comment
Share on other sites

Guest cherryaa

This will be very quick and only a little help, but .... You simply can't include php directly in the template files. You can, however, create one of those {} placeholders relatively easily (I may regret saying that!) by calling your include to one of the .inc files and then copying the way Alistair does his assignments.

I seem to remember having to add a line to index.php - the one in the root directory - as well. I've only done this once; with luck a CC expert will fill you in a bit more!

Hope this gets you started, anyway :sourcerer:

Edited to add: Or, you could get it running on a page of its own & then ajax it in (or use an iframe). Which is probably what I'd do.

Cherry.

Link to comment
Share on other sites

Guest Jon Bartus

This will be very quick and only a little help, but .... You simply can't include php directly in the template files. You can, however, create one of those {} placeholders relatively easily (I may regret saying that!) by calling your include to one of the .inc files and then copying the way Alistair does his assignments.

I seem to remember having to add a line to index.php - the one in the root directory - as well. I've only done this once; with luck a CC expert will fill you in a bit more!

Hope this gets you started, anyway :sourcerer:

Edited to add: Or, you could get it running on a page of its own & then ajax it in (or use an iframe). Which is probably what I'd do.

Cherry.

Yeah, I was hoping not to have to iframe (or ajax) it in...

I am disappointed to hear that I can't include it directly, could you perchance assist with creating a {} placeholder as quite honestly this methodology is beyond my experience. Just a simple explanation of how I would do that would more than suffice.

Regards,

Jon

Link to comment
Share on other sites

Guest cherryaa

OK, you've probably figured it out by now, but I've just been back over it & am posting here for posterity (mainly in case I forget again!).

Caveat: I was not following any instructions and may have made an error. But my simple test works fine on our long-suffering test site.

New file: includes/boxes/testInclude.php

<?php 



$newContent = "Included this!";





$box_content=new XTemplate("skins/".$config['skinDir']."/styleTemplates/boxes/testInclude.tpl");



		$box_content->assign("NEWSTUFF",$newContent);

		$box_content->parse("test_inc");

		$box_content = $box_content->text("test_inc");

		

?>




New file: styleTemplates/boxes/testInclude.tpl


<!-- BEGIN: test_inc -->

<div class="boxTitleLeft">TEST INCLUDE</div>

<div class="boxContentLeft">

	<span class="txtCopy">

	<strong>The file said:</strong> {NEWSTUFF}<br />

  </span>

</div>

<div class="boxFootLeft">&nbsp;</div>

<!-- END: test_inc -->




Edited file /index.php, line 180


	

	include("includes/boxes/testInclude.inc.php");

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




Edited file styleTemplates/global/index.tpl


					{TEST_INC}

					{RANDOM_PROD}

					{POPULAR_PRODUCTS}

So now there definitely is a thread on it :sourcerer:

Cherry.

Link to comment
Share on other sites

  • 4 weeks later...

Thanks Cherryaa for posting this... I found it really helpful.

If anyone is wanting to do this on version 4, I used this guide but with the following amendments... and it all seems to be ok!

Instead of adding the include code to /index.php

add it to /includes/global/index.inc.php

and change to

require_once"includes".CC_DS."boxes".CC_DS."testinclude.inc.php";

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




And in includes/boxes/testInclude.php

change line 6 to 


$box_content=new XTemplate("boxes".CC_DS."testinclude.tpl");

Hope that helps!

Rachael

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...