Jump to content

Do you Need to know how to create more Global Templates - Learn How He


Guest pghtech

Recommended Posts

Guest pghtech

Here is a question I needed answered, found numerous people posting about it on this forum and with no responses. So I thought would help those that might come here for answers on creating additional global templates. Yes, I understand this forum is specific to the core functionality of CubeCart.

If you are like me and the global/index.tpl template is to confining for your design ideas, you probably will need to generate new global templates that you can customize to look different. Or maybe you simply want your homepage to look different than all other pages that use the global/index.tpl template, this is how you can do it.

I am not a PHP expert, so I am going to provide just the necessities to accomplish this. If your design or purpse of creating a different global template is not answered here or you don't know how, you will need to look somewhere else.

First thing you need to do is create the global template and associated .php files. As mentioned, I am not an PHP coder, and I basically want to keep all functionality of the default includes/global/index.inc.php and skins/<yourskinName>/styleTemplates/global/index.tpl . So simply make a copy of each of these right in the directory they are now. Rename each file as you like.

For example, for creating a specific homepage global template, rename each copy of index.inc.php and index.tpl to home.inc.php and home.tpl.

You will need to do the above steps for every how many global templates you want to create. I would suggest just starting out with doing one like creating the individual homepage to get a better understanding.

THEN:

Simply find the associated PHP file for global/index.tpl found here: /includes/global/index.inc.php.

In the file locate the code:

$body = new XTemplate ("global".CC_DS."index.tpl");




And Comment it out putting a "#" in front of it so we don't loose it



Then add below it:


 if($config['skinDir'] == '<your skin name here>') {

	if($_GET['_a'] == '<CubeCart Template name here>') {

		$body = new XTemplate ("global".CC_DS."yourTemplateName.tpl");	

	} else if($_GET['_a']) {

		$body = new XTemplate ("global".CC_DS."index.tpl");

	} else {

		$body = new XTemplate ("global".CC_DS."home.tpl");

	}

} else {

	$body = new XTemplate ("global".CC_DS."index.tpl");

}

[code]



A couple items you need to change.  I put in the first main "IF" statement, because if you change the template that the home page loads in, it will change it for ALL skins.  So if you want to make sure it only occurs for your skin, the $config['skinDir'] will ensure it only loads your skin's homepage into a different global template.  In conjunction with this, is the last "$body =" statement.  This is the default template if you load a different skin than yours in your admin -> general settings.



You will see where it says 

[code]

 if($config['skinDir'] == '<your skin name here>') {




You need to change where it says <your skin name here> to the name of your skin (make sure to remove the "<>" as well.

Example"


 if($config['skinDir'] == 'coolskin') {




The next change you need to make is 


if($_GET['_a'] == '<CubeCart Template name here>') {




Where it says "<CubeCart Template name here>".  This would be where you specify the CubeCart template that you want to load into your own custom template.  For example, I want the template that loads A specific product details to NOT load in the index template, but into my own global template so I can control the way this specific page looks.  I would change this to:


if($_GET['_a'] == 'viewProd') {




This then says that if the CubeCart template that is being loaded equals the name "viewProd" (the actual file name is viewProd.tpl) then load it in my global template.  To load it in your custom global template, comes the next line you need to alter


$body = new XTemplate ("global".CC_DS."yourtemplatename.tpl");




You would specify the template name of your custome global template here.  For my example about loading the CubeCart individual product details template (viewProd.tpl) in my own custom global template would be like this:


$body = new XTemplate ("global".CC_DS."product.tpl");






You can add as many "else If" statements for as many custom global templates you have.  For example, I wanted to load the viewProd.tpl and login.tpl CubeCart templates into a custom global template, so I have a few "else If" statements:


if($config['skinDir'] == 'db') {

	if($_GET['_a'] == 'viewProd') {

		$body = new XTemplate ("global".CC_DS."product.tpl");	

	} else if($_GET['_a'] == 'login') {

		$body = new XTemplate ("global".CC_DS."product.tpl");	

	} else if($_GET['_a']) {

		$body = new XTemplate ("global".CC_DS."index.tpl");

	} else {

		$body = new XTemplate ("global".CC_DS."home.tpl");

	}

} else {

	$body = new XTemplate ("global".CC_DS."index.tpl");

}




NOTE: IF YOU ARE NOT CREATING A NEW HOMEPAGE GLOBAL TEMPLATE, MAKE SURE TO REMOVE THE LINE FROM MY EXAMPLE CODE:


else {

		$body = new XTemplate ("global".CC_DS."home.tpl");




And on the above "Else if" statement change it to only "else {


} else if($_GET['_a']) {

		$body = new XTemplate ("global".CC_DS."index.tpl");




becomes




} else {

	$body = new XTemplate ("global".CC_DS."index.tpl");

FINAL NOTE:

If you run into any problems, all you have to do is come back into this index.inc.php file, remove the added code AND remove the "#" from in front of the first statement we changed at the beginning of this post.

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...
Guest charleyramm

super useful.

I've set mine to select a template based on docid. I'm using it to run Google Website Optimizer.

#$body = new XTemplate ("global".CC_DS."index.tpl");



if($config['skinDir'] == 'myskin') {

	if($_GET['_a'] == 'index') {

		$body = new XTemplate ("global".CC_DS."home.tpl");  

	} else if($_GET['docId'] == '17') {

		$body = new XTemplate ("global".CC_DS."variation.tpl");   

	} else if($_GET['docId'] == '13') {

		$body = new XTemplate ("global".CC_DS."conversion.tpl"); 

	} else if($_GET['_a']) {

		$body = new XTemplate ("global".CC_DS."index.tpl");

	} else {

		$body = new XTemplate ("global".CC_DS."home.tpl");

	}

} else {

	$body = new XTemplate ("global".CC_DS."index.tpl");

}

This is hugely helpful. I wish it was simpler to do this with Cubecart.

Wordpress has it built in to the gui. You create a new template file, then select it from the page editor.

Link to comment
Share on other sites

  • 1 month later...
Guest sevenwear

Awesome post - I was struggling to think of the best way to add content outside of {PAGE_CONTENT}, but this method was easy and fare more elegant. Well done!

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

Awesome Post!

I had almost given up searching on how to create a custom homepage.

It only took me 5 minutes to make the changes, very clear instructions as well. :rolleyes: :yeahhh:

Link to comment
Share on other sites

Guest jon123

Theres an awful lot of unanswered posts from people needing help with Cubecart code.

Im having terrible trouble getting advice and or a response to my posts on both this forum and the other one cubecartforums.org. I cant get anyone to advice or I get one or no response to any of my forum posts in both forums.

Link to comment
Share on other sites

Theres an awful lot of unanswered posts from people needing help with Cubecart code.

Im having terrible trouble getting advice and or a response to my posts on both this forum and the other one cubecartforums.org. I cant get anyone to advice or I get one or no response to any of my forum posts in both forums.

Are you posting in the correct places with enough information? because this forum is not the correct place to post a complaint about replies :) it's very off topic.
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...