Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Simple Guide to Creating Basic PHP Pages using Templates

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-20-2010, 10:02 AM
  pairodimes's Avatar 
pairodimes pairodimes is offline
 

Advanced Member
  
Join Date: Dec 2007
Posts: 50
 

Post Simple Guide to Creating Basic PHP Pages using Templates

I originally wrote this for my blog - but I thought I would share - I had a hard time finding this information how through the forums so I here we go a new thread.


I don't know if I just missed the section that details how to create a PHP page in X-cart so I finally just broke down and decided to write this article.
Here was my scenario - I wanted to create a static PHP page that could access from the x-cart site root. I also wanted the page to use the main template design for the site - so things like shopping cart totals and customer login info were still being displayed.


Things to know:
1.) X-Cart uses SMARTY template engine - I can't stand it - but whatever.
2.) X-Cart uses a directory structure that keeps all template files in one location (yourroot/skin1/)
3.) PHP scripts are executed from outside of this /skin1/ directory - try using a the folder called Modlues and add your custom file there.
4.) The logic for creating a template is:
yournewpage.php --> skin1/customer/home_main.tpl --> include customer/yournewpage.tpl --> skin1/customer/yournewpage.tpl
I create sitemap.php as my example.
1.) Lets create sitemap.php


Code:
<?php # # $Id: sitemap.php,v 1.0 2010/01/11 18:09:11 pdma Exp $ # require "./auth.php"; require $xcart_dir."/include/categories.php"; $smarty->assign("_sitemap_",$_new_page_); $smarty->assign("main","_sitemap_"); func_display("customer/home.tpl",$smarty); ?>


If you look at the last line - we just captured all of the necessary SMARTY variables and shoved them into the "customer/home.tpl" - this template calls another template into the center content area of your page "customer/home_main.tpl"
So lets alter the "customer/home_main.tpl" page - towards the last line include this just before the final "else" statement


Code:
{elseif $main eq "_sitemap_"} {include file="customer/sitemap.tpl"}


Ok - so now we are injecting the "customer/sitemap.tpl" into the main content area of our web page - with all the fancy design we spent so long to perfect.
So lets create and add some content to the "customer/sitemap.tpl" in our /skin1/ directory


Code:
{* $Id: sitemap.tpl,v 1.0 2010/01/11 09:52:43 pdma Exp $ vim: set ts=2 sw=2 sts=2 et: *} {capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} {foreach from=$categories_menu_list item=c} <h2><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></h2> {assign var=in value=$c.categoryid} <ul> {foreach from=$allsubcategories.$in item=cat} {if $cat.parentid eq $c.categoryid} <li><a href="home.php?cat={$cat.categoryid}" class="subMenuItem">{$cat.category}</a></li> {/if} {/foreach} </ul> {/foreach} {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}



On this page we used some standard x-cart variables to display Categories and Subcategories - from here you can extend it to include template variables so you can even more granular control.
- example try adding a language variable to the code just after the last SMARTY include line


Code:
{$lng.lbl_shopinfo}


Like I mentioned before you can keep extending this to include simple includes to other templates such as a template to where PHP can bve executed - such as in the Modules directory outside of /skin1/


Code:
{include_php file="modules/Sitemap/sitemap.php"}


I hope this helps - if you know of a better place to find this documentation - would you please let me know.
__________________
------
Brian

Portland web design / development
X-Cart 4.1.9 (a few carts)
X-Cart 4.2.0 (1 cart so far)
Reply With Quote

The following 5 users thank pairodimes for this useful post:
am2003 (07-10-2010), AusNetIT (04-30-2010), matallen (02-25-2010), pia (05-14-2010), vasilis (03-08-2010)
  #2  
Old 01-20-2010, 10:04 AM
  pairodimes's Avatar 
pairodimes pairodimes is offline
 

Advanced Member
  
Join Date: Dec 2007
Posts: 50
 

Default Re: Simple Guide to Creating Basic PHP Pages using Templates

PS - this is also a pretty helpful post for those looking to create a Sitemap Page with automatic Categories and Subcategories.

For an XML sitemap I always recommend WebSiteCM CDSEO Pro - amazing.
__________________
------
Brian

Portland web design / development
X-Cart 4.1.9 (a few carts)
X-Cart 4.2.0 (1 cart so far)
Reply With Quote
  #3  
Old 06-22-2010, 05:54 AM
 
inteliboy1 inteliboy1 is offline
 

Member
  
Join Date: Jun 2010
Posts: 27
 

Default Re: Simple Guide to Creating Basic PHP Pages using Templates

This is all sorts of awesome - v. helpful, thanks for sharing.
__________________
X-Cart Pro
4.4
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:58 AM.

   

 
X-Cart forums © 2001-2020