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}></div><{$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 an active template
back to dev:Tutorials

![[Main Page]](/modules/mediawiki/images/mediawiki.png)






