Jump to content

Using PHP includes in global/index.tpl


Guest marklyon

Recommended Posts

Guest marklyon

Cant you just use the standard CC menu and style it as you want ??

I haven't looked into it to be honest. I'm trying to make everything low maintenance so that when I change one php file it reflects site-wide.

Link to comment
Share on other sites

Guest tyler-bishop

Cant you just use the standard CC menu and style it as you want ??

I haven't looked into it to be honest. I'm trying to make everything low maintenance so that when I change one php file it reflects site-wide.

Thats how the templates function, if you edit index.tpl it will reflect almost all the pages.

Link to comment
Share on other sites

Guest marklyon

Thanks tyler-bishop

The only problem is when I edit the index.tpl to include the following code:

<?php include_once("'path_to_my_includes_folder'/menu.php"); ?>

It doesn't work. At the moment CubeCart is really well integrated into the design of the site and I'd like to use the same menu on the e-commerce pages as I do on the rest of the site - hence using the includes as it will be fantastic to edit just one file.

I hope I've explained myself a little better.

Cheers

Link to comment
Share on other sites

Guest Brivtech

You're almost there!

You need to put the php code within the inc.php file, and then parse it to the template file!

So, in your example, assuming it's the global/index.tpl file...

open: includes/global.index.inc.php

Then add in somewhere where there are similar lines:

$menu_code = "whatever code you put in the file that you were trying to include";

$body->assign("MY_MENU",$menu_code);

Then, open up your index.tpl file that you first mentioned, and replace the line of php that you added with this:

{MY_MENU}

Save and upload, and where you have the item in the curly brackets, it will be passed (parsed) the information from the inc.php file that does all the processing work.

If you're still unsure about this, have a look at some of the other variables there, and see how they have been programmed.

Each .tpl file has a respective inc.php file that processes the database information and passes it to the template.

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
Guest Astroman

Hi, I'm trying to do something similar so I thought I'd post it here. Can you tell me how I would include the current year in a tpl file? Usually in tpl files I write something like {PHP}echo date ('Y');{/PHP} but that doesn't work with Cube Cart, so I guess I have to use a different method?

Link to comment
Share on other sites

Guest EverythingWeb

Yeah, you will need to assign the value in the PHP:

$body->assign("DATE", date('Y-m-d'));

Then, in the .tpl, use: {DATE} where you want it.

Link to comment
Share on other sites

Guest Astroman

Yeah, you will need to assign the value in the PHP:

$body->assign("DATE", date('Y-m-d'));

Then, in the .tpl, use: {DATE} where you want it.

Thanks, I will give that a go.

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