Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules

Search

Donate to XOOPS!

Please select an amount to donate


Do you want your username revealed with your donation?
Yes - List me as a Generous Donor
No - List my donation as from an Anonymous Donor


Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

admin Arabic banner block Christmas comments cumulus DayDawn dhsoft e-Commerce E-Learning Git Google GUI hacks instant-zero jQuery module mygalleries news Nordic Olédrion oxygen PageRank PHP rmcommon security SEO simple-XOOPS Smarty sport tag Theme tutorial wiki WOX xoops XoopsEngine ZendFramework

New Users

Registering user

# 133948

guilhermeans

Welcome to XOOPS!
[Main Page]

MD-Tutorials

From XOOPS Web Application System

Main Page | Recent changes | Edit this page | Page history | Switch to MediaWiki mode

Printable version | Disclaimers | Privacy policy
Category: ModuleDevelopment

This page needs editing

Module Development Tutorials,




- http://dev.xoops.org/dl/tinyeditor/docs/tinyeditor100.pdf
- http://dev.xoops.org/dl/tinyeditor/docs/tinyeditor1RC1.pdf
- http://dev.xoops.org/dl/tinyeditor/docs/tinyeditor_v101_en.pdf
- http://dev.xoops.org/dl/mx-directory/docs/MXD_RSS_Admin_Guide.pdf
- http://dev.xoops.org/dl/xhelp/docs/xhelp_user_documentation.pdf
- http://dev.xoops.org/dl/jiareports/docs/ReadMe.txt
- http://dev.xoops.org/dl/mx-directory/docs/MXD_Blocks_Admin_Guide.pdf
- http://dev.xoops.org/dl/xoops-fa/docs/system.pdf
- http://dev.xoops.org/dl/xoops_qa/docs/qa_roadmap_20050107-1.html
- http://dev.xoops.org/dl/xhelp/docs/Event_Service.txt
- http://dev.xoops.org/dl/cstand/docs/DB%20Design.pdf

Contents

2. Using a simple template file

In the previous example we wrote a string to the screen using echo. That may be fine for simple sites, but using a simple template will make the output blend better into the site layout. We'll introduce templates by outputting the string from the last example, but have in mind that this still isn't the "right" way to do it, as the HTML is still buried inside the PHP code.

A template is NOT a complete HTML file. It contains just the HTML code that you want to appear inside your module, and it does NOT contain any <head> or <body> tags.

Follow these steps to output our table using a minimal template:

1.Create a folder named templates with a file "myTemplate.html" inside it containing this line:

  • <{$content}>

2.Edit our xoops_version.php file to contain this line:

  • $modversion['templates'][1]['file'] = "myTemplate.html";
  • $modversion['templates'][1]['description'] = "Our template file";

3.Edit our index.php file to use the template, and assign the output to the template instead of using echo:

  • <?php //index.php
  • require_once("../../mainfile.php");
  • include_once "include/functions.php";
  • global $xoopsTpl;
  • // this line must be defined BEFORE header.php
  • $xoopsOption['template_main'] = "myTemplate.html";
  • include XOOPS_ROOT_PATH."/header.php";
  • $str = getTable();
  • $xoopsTpl->assign("content", $str);
  • include XOOPS_ROOT_PATH."/footer.php";
  •  ?>

We see here that our string is assigned to the global Xoops object xoopsTpl as a variable named "content". The contents of this variable will replace the <{$content}> in the template file.

This may be an OK way of doing thing if we're building a module with lots of pages where the layout is dynamic and we want to change things in php. But most of the HTML is still inside the php code, and we'd like to separate layout from content, so that's what we'll do next.

Other parts:

1.2.1 Using echo
1.2.3 Using an active template


Retrieved from "http://xoops.org/modules/mediawiki/index.php/MD-Tutorials"

This page has been accessed 5,279 times. This page was last modified 20:36, 9 February 2008. Content is available under XOOPS Web Application System.