X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Simple Guide to Creating Basic PHP Pages using Templates (https://forum.x-cart.com/showthread.php?t=51875)

pairodimes 01-20-2010 10:02 AM

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.

pairodimes 01-20-2010 10:04 AM

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.

inteliboy1 06-22-2010 05:54 AM

Re: Simple Guide to Creating Basic PHP Pages using Templates
 
This is all sorts of awesome - v. helpful, thanks for sharing.


All times are GMT -8. The time now is 04:16 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.