网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > X-Cart
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 153.99.38.207
Old 2015-06-10, 10:21 PM
Hansville Hansville is offline
初级会员
 
Join Date: 2011-06-26
Posts: 2
Hansville 现在声名狼藉
Default 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"}
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
X-Cart Multiple Input Validation Holes Permit SQL Injection and Cross-Site Scripting topvip X-Cart 0 2009-07-21 10:03 AM
用php语言来编写shell脚本 car 代码交流 0 2008-05-05 08:09 PM
Php教程.经验技巧(上) sunshine 代码交流 0 2006-12-15 08:13 PM
Php入门速成 smiling 代码交流 0 2006-12-15 07:30 PM
php.ini中文解释 sunshine 服务器环境搭建 0 2006-02-04 11:05 PM

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 02:08 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.