OSCommerce_3 使用的模板技术介绍(英文)

Template Class (osC_Template)

The template class (osC_Template) builds each page with the default or selected template design and controls where the elements of a page are to be shown, e.g. the header, footer, main content, side boxes, and content modules.

Content Classes and Content Page Files

Each page is accessed through a group based on the page requested where a content class is loaded that inspects the environment and loads a defined content page file. A content class code name can be passed as a parameter in the URL address to override the default content class from loading. The structure of a URL page request is defined as:

http://www.example.com/oscommerce/[GROUP].php?[CONTENT CLASS]

The group file defines a default content class to load if none is passed as a parameter in the URL address.

Content classes are responsible for inspecting the environment to load a defined content page file and are located in the following directory:

/httpdocs/oscommerce/includes/content/[GROUP]/[CONTENT CLASS].php

The online store index page is requested as:

http://www.example.com/oscommerce/index.php

This loads the default content class defined in the index group as no content class code name was passed as a parameter. The index.php file contains the following code to setup and load the defined content module:

<?php
  $osC_Template = osC_Template::setup('index');
?>

This loads the index content class from the following directory:

/httpdocs/oscommerce/includes/content/index/index.php

If a content class code name was passed as a parameter in the URL address it would be loaded within the osC_Template::setup() class method rather than the default content class.

For example:

http://www.example.com/oscommerce/index.php?manufacturers

This will load the manufacturers content class from the index group located at:

/httpdocs/oscommerce/includes/content/index/manufacturers.php

The primary function of a content class is to inspect the environment to load a defined content page file. Content page files are located in the following directory:

/httpdocs/oscommerce/templates/[TEMPLATE]/content/[GROUP]/

A simple content class for the online store index page is:

<?php
  class osC_Index_Index extends osC_Template {
    var $_module = 'index',
        $_group = 'index',
        $_page_title,
        $_page_contents = 'index.php',
        $_page_image = 'table_background_default.gif';

    function osC_Index_Index() {
      global $osC_Language;

      $this->_page_title = sprintf($osC_Language->get('index_heading'), STORE_NAME);

      if ( isset($_GET['list']) && ( $_GET['list'] == 'column' ) ) {
        $this->_page_title = $osC_Language->get('index_column_heading');
        $this->_page_contents = 'index_column.php';
      }
    }
  }
?>

The $_page_contents class variable defines a default content page to load and can be overwritten within the class constructor. By default this would load the following page content file:

/httpdocs/oscommerce/templates/[TEMPLATE]/content/index/index.php

Content classes are given the following class name:

osC_[GROUP]_[CONTENT CLASS CODE NAME]

The first letters of the group and content class code names are capitalized. The manufacturers content class described in a previous example would have the following class name:

osC_Index_Manufacturers

Page Properties

Page Titles

The title of the page is defined in the content class $_page_title variable and can be retrieved with the getPageTitle() class method:

<title><?php echo $osC_Template->getPageTitle(); ?></title>

The existence of the page title can be checked and be externally overwritten with the hasPageTitle() and setPageTitle() class methods:

<?php
  if ( !$osC_Template->hasPageTitle() ) {
    $osC_Template->setPageTitle('New Page Title');
  }
?>

Page Tags (Meta Elements)

Meta elements can be associated with a page to influence search engine rankings and are placed within the <head> section in the HTML source of the page with the getPageTags() class method:

<html>
<head>

<?php
  if ( $osC_Template->hasPageTags() ) {
    echo $osC_Template->getPageTags();
  }
?>

</head>
</html>

Tags can be added to a page with the addPageTags() class method:

<?php
  $osC_Template->addPageTags('keywords', 'apples');
?>

The first parameter is the meta group to add the meta elements to and the second parameter contains the meta element value. If multiple calls to addPageTags() are made using the same meta group, the multiple meta element values will be separated by commas when displaying the page tags.

Javascript

Javascript can be added to a page in three ways and are placed within the <head> section in the HTML source of the page. The hasJavascript() class method can check if Javascript is to be added to the page and is added with the getJavascript() class method:

<html>
<head>

<?php
  if ( $osC_Template->hasJavascript() ) {
    $osC_Template->getJavascript();
  }
?>

</head>
</html>

The three methods available to add Javascript to a page are described as follows.

Javascript Blocks

Blocks of Javascript can be added with the addJavascriptBlock() class method:

<?php
  $javascript = '<script language="javascript">alert("Hello!");</script>';

  $osC_Template->addJavascriptBlock($javascript);
?>
External Javascript Files

External Javascript files can be referenced to with the addJavascriptFilename() class method:

<?php
  $osC_Template->addJavascriptFilename('/httpdocs/oscommerce/ext/js/script.js');
?>
Externally Built PHP Javascript

Javascript that is built with PHP in an external file is included in the page with the addJavascriptPhpFilename() class method:

<?php
  $osC_Template->addJavascriptPhpFilename('/httpdocs/oscommerce/ext/js/script.php');
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值