Community Documentation

XTemplate to PHPTemplate conversion

Last updated December 24, 2010. Created by gordon on May 4, 2005.
Edited by Andrew Answer, SLIU, Dublin Drupaller, sepeck. Log in to edit this page.

Firstly rename the xtemplate.xtmpl file to original.xtmpl so that the theme is no longer a xtemplate theme.

Creating page.tpl.php
  1. copy original.xtmpl to page.tpl.php
  2. Remove the node, comment, box, and block sections. In the place of these sections add the following code
    <?php print $content; ?>
  3. Change all the "{" characters to "<?php print $"
  4. Change all the "}" characters to "; ?>"
  5. Change the "$footer" to "$closure"
  6. Change "$message" to "$messages"
  7. As the primary and secondary links in phptemplate are arrays you will need to change them from "print $primary_links;" to "print theme('links', $primary_links);". Also the same needs to be done for secondary links.
  8. In the blocks section we need to change the $blocks to either $sidebar_left or $sidebar_right depending on which side of the content it is on.
  9. Add the following around <div id="sidebar-left">...</div>. "<?php if ($sidebar_left) { ?>...<?php } ?>" Repeat same for <div id="sidebar-right">. It may be "td" instead of "div", depends from design.
  10. Add the following around <div id="mission">...</div>. "<?php if ($mission) { ?>...<?php } ?>"
  11. Replace search block from <form> to </form> with <?php print $search_box; ?>
Creating node.tpl.php
  1. Copy the node section from the original.xtmpl to a new file node.tpl.php
  2. As before change all the "{" and "}" characters to "<?php print $" and "; ?>" respectively.
  3. change $link to $node_url.
  4. Change "$taxonomy" to "$terms"
  5. Change "print $sticky;" to "if ($sticky) { print " sticky"; }"
  6. Change "print $picture;" to "if ($picture) { print $picture; }"
  7. As both the page.tpl.php and node.tpl.php have the displaying of the title twice. To get around this you need to only display the header when $page = 0. You will need to add the following around the <h2 class="title">...</h2>. "<?php if ($page == 0) { ?>...<?php } ?>"
Creating comment.tpl.php
  1. Copy the comment section from the original.xtmpl to a new file comment.tpl.php
  2. As before change all the "{" and "}" characters to "<?php print $" and "; ?>" respectively.
  3. Change "print $picture;" to "if ($picture) { print $picture; }"
  4. Also just to be clean, you may want to change the displaying of the new so it will only show when the $new != ''. You will need to add the following around the <span class="new">...</span>. "<?php if ($new != '') { ?>...<?php } ?>"
Create block.tpl.php
  1. Copy the block section from the original.xtmpl to a new file block.tpl.php
  2. Change all the "{" and "}" characters to "<?php print $block->" and "; ?>" respectively.
  3. Then change the $block->title to $block->subject.
Create box.tpl.php
  1. Copy the box section from the original.xtmpl to a new file box.tpl.php
  2. As before change all the "{" and "}" characters to "<?php print $" and "; ?>" respectively.

If you have any JS files or pictures included into original design, you should to change path like src="themes/..." to src="<?php print $base_path ?>themes/..." to work design properly with "clean URLs" feature.

Comments

Teaser/main headers

To ensure that teaser headers are only displayed on the front page, and not twice on individual node pages, use:

    <?php if ($page == 0): ?>
      <h2><a href="/<?php print $node_url ?>"><?php print $title ?></a></h2>
    <?php endif; ?>

in node.tpl.php

---
paul byrne
web monkey - http://www.leafish.co.uk/

Unclear instruction

I think this is what needs to be put in for the new to show only when comment is new:

<?php if ($comment->new) : ?><span class="new"> *<?php print $new ?></span><?php endif; ?>

I had to go looking for it, so maybe this will save someone the trouble.

Wow. This is a fantastic handbook page.

Thanks so much for writing this - (and everyone's comments were very helpful as well!).

Update: After a little more time to go through my own templates and address a couple naggling things I realized a couple more tips that might help someone who wants to convert their template:

I'll preface by saying that one could just read the next paragraph I've written below and try and start from there, but it is probably a better idea to start with the steps outlined at the top of the page because it will familiarize you with the basics of what's going on - then afterwards do what is mentioned below in order to clean things a bit.

Unless you've made special modifications to your xtemplate you can probably get away with just copying over comment.tpl.php, box.tpl.php, block.tpl.php, and node.tpl.php from a recent phptemplate version of Blue Marine. And then go through page.tpl.php and see what matches what and copy and paste appropriately from each other.

=====

Drupal hosting

nobody click here