diff --git a/README.md b/README.md
new file mode 100644
index 0000000..695eb59
--- /dev/null
+++ b/README.md
@@ -0,0 +1,8 @@
+# CAUTION!!!!!!!!!
+
+PHPTemplate doens't provide any autoescaping, so you would need to provide your own escaping.
+
+# Installation
+Just provide the template engine along to a theme using it
+
+
diff --git a/block.tpl.php b/block.tpl.php
deleted file mode 100644
index ca670db..0000000
--- a/block.tpl.php
+++ /dev/null
@@ -1,4 +0,0 @@
-<div class="<?php print "block block-$block->module" ?>" id="<?php print "block-$block->module-$block->delta"; ?>">
-  <h2><?php print $block->subject ?></h2>
-  <div class="content"><?php print $block->content ?></div>
-</div>
diff --git a/box.tpl.php b/box.tpl.php
deleted file mode 100644
index e19ffba..0000000
--- a/box.tpl.php
+++ /dev/null
@@ -1,4 +0,0 @@
-<div class="box">
-  <h2><?php print $title ?></h2>
-  <div class="content"><?php print $content ?></div>
-</div>
diff --git a/comment.tpl.php b/comment.tpl.php
deleted file mode 100644
index 69962ae..0000000
--- a/comment.tpl.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<div class="comment <?php print ($comment->new) ? 'comment-new' : '' ?>">
-<?php if ($comment->new) : ?>
-  <a id="new"></a>
-  <span class="new"><?php print $new ?></span>
-<?php endif; ?>
-
-<div class="title"><?php print $title ?></div>
-  <?php print $picture ?>
-  <div class="author"><?php print $submitted ?></div>
-  <div class="content"><?php print $content ?></div>
-  <?php if ($picture) : ?>
-    <br class="clear" />
-  <?php endif; ?>
-  <div class="links"><?php print $links ?></div>
-</div>
diff --git a/default.tpl.php b/default.tpl.php
deleted file mode 100644
index 8008a2c..0000000
--- a/default.tpl.php
+++ /dev/null
@@ -1 +0,0 @@
-<!-- PHPTemplate was instructed to override the  <?php print $hook ?> theme function, but no valid template file was found. -->
diff --git a/node.tpl.php b/node.tpl.php
deleted file mode 100644
index 6af267d..0000000
--- a/node.tpl.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">
-  <?php if ($page == 0): ?>
-    <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
-  <?php endif; ?>
-  <?php print $picture ?>
-  
-  <div class="info"><?php print $submitted ?><span class="terms"><?php print $terms ?></span></div>
-  <div class="content">
-    <?php print $content ?>
-  </div>
-<?php if ($links): ?>
-
-    <?php if ($picture): ?>
-      <br class='clear' />
-    <?php endif; ?>
-    <div class="links"><?php print $links ?></div>
-<?php endif; ?>
-</div>
diff --git a/phptemplate.engine b/phptemplate.engine
index 6db562c..c27e93e 100644
--- a/phptemplate.engine
+++ b/phptemplate.engine
@@ -1,370 +1,59 @@
 <?php
-// $Id$
-
-function phptemplate_init($template) {
-  require_once(realpath('themes/engines/phptemplate/template.php'));
-  $engine_code = variable_get('phptemplate_extra_logic', array());
-  $file = dirname($template->filename) . '/template.php';
-  if (file_exists($file)) {
-    include_once($file);
-  }
-}
-
-function phptemplate_templates($directory = 'themes') {
-  return system_listing('^page\.tpl\.php$', $directory, 'filename');
-}
-
 
 /**
- * Execute a template engine call.
- *
- * Each call to the template engine has two parts. Namely preparing
- * the variables, and then doing something with them.
- *
- * The first step is done by all template engines / themes, the second
- * step is dependent on the engine used.
- *
- * @param $hook
- *   The name of the theme function being executed
- * @param $vars
- *   A sequential array of variables passed to the theme function.
- * @param $file
- *   A suggested template file to use.
- * @return
- *  The HTML generated by the template system.
+ * @file
+ * Handles integration of PHP templates with the Drupal theme system.
  */
-function _phptemplate_callback($hook, $vars = array(), $file = null) {
-
-  $vars = array_merge($vars, _phptemplate_default_variables($hook, $vars));
-
-  // Allow specified variables to be overridden
-  if (function_exists('_phptemplate_variables')) {
-    $vars = array_merge($vars, _phptemplate_variables($hook, $vars));
-  }
-
-  if ($vars['template_file']) {
-    $file = $vars['template_file'];
-  }
-  
-  if (function_exists('_phptemplate_' . $hook)) {
-    return call_user_func('_phptemplate_' . $hook, $vars, $file);
-  }
-  elseif (function_exists('_phptemplate_default')) {
-    return call_user_func('_phptemplate_default', $hook, $vars, $file);
-  }
 
-}
+use Drupal\Core\Extension\Extension;
 
 /**
- * Counts how many times certain hooks have been called
- *
- * Sidebar left / right are special cases.
+ * Implements hook_init().
  */
-function _phptemplate_default_variables($hook, $vars) {
-  static $count = array();
-  $count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1;
-  $vars['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
-  $vars['seqid'] = $count[$hook]++;
-
-  global $sidebar_indicator;
-  if ($hook == 'block') {
-    $count['block_counter'][$sidebar_indicator] = is_int($count['block_counter'][$sidebar_indicator]) ? $count['block_counter'][$sidebar_indicator] : 1;
-    $vars['block_zebra'] = ($count['block_counter'][$sidebar_indicator] % 2) ? 'odd' : 'even';
-    $vars['block_seqid'] = $count['block_counter'][$sidebar_indicator]++;
-  }
-
-  // Tell all templates where they are located.
-  $vars['directory'] = path_to_theme();
-  
-  if (drupal_get_path_alias($_GET['q']) == variable_get('site_frontpage', 'node')) {
-    $vars['is_front'] = true;
-  }
-
-  return $vars;
-}
-
-function phptemplate_features() {
-  return array(
-       'logo',
-       'toggle_name',
-       'toggle_search',
-       'toggle_slogan',
-       'toggle_mission',
-       'toggle_primary_links',
-       'toggle_secondary_links',
-       'toggle_node_user_picture',
-       'toggle_comment_user_picture');
+function phptemplate_init(Extension $theme) {
+  $theme->load();
 }
 
 /**
- * PHPTemplate specific theme settings
- *
- * Due to differences in the handling of primary and secondary links, these settings need to be seperately specified for phptemplate based themes.
- *
- * @returns
- *   HTML code for the phptemplate engine specific form segment on theme configuration pages.
+ * Implements hook_theme().
  */
-function phptemplate_settings() {
-  $header = array(t('link text'), t('url'), t('description'));
-  $form = t('<p>Due to incompatibilies in the handling of primary, and secondary links in PHPTemplate, these links need to specified seperately using the form below. Even though this is on the theme-specific configuration page, these settings will take affect in all themes using PHPTemplate.</p>');
-
-  foreach (array('Primary', 'Secondary') as $utype) {
-    $rows = array();
-
-    //Use $utype field , and strtolower() it to get the type field.. to avoid issues with ucfirst() and unicode.
-    $type = strtolower($utype);
-
-    //Increment the link count, if the user has requested more links.
-    if (variable_get('phptemplate_' . $type . '_links_more', false)) {
-      variable_del('phptemplate_' . $type . '_links_more');
-      variable_set('phptemplate_' . $type . '_link_count', variable_get('phptemplate_' . $type . '_link_count', 5) + 5);
-    }
-
-    //Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format.
-    $value = variable_get('phptemplate_' . $type . '_links', array());
-
-    //Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
-    $count = variable_get('phptemplate_' . $type . '_link_count', 5);
-    $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']);
-    if (variable_get('phptemplate_' . $type . '_link_count', 5) != $count) {
-      variable_set('phptemplate_' . $type . '_link_count', $count);
-    }
-
-    for ($i = 0; $i < $count; $i++) {
-      $row = array();
-      foreach (array('text', 'link', 'description') as $field) {
-        $row[] = form_textfield('', 'phptemplate_' . $type . '_links][' . $field . '][' . $i, $value[$field][$i], 15, 90);
-      }
-      $rows[] = $row;
-    }
-    $form .= form_item(t("$utype links"), theme("table", $header, $rows), t('You can specify your _TYPE_ links here, one link per line.<br /> The link text field is the text you want to link.<br /> The url field is the location the link points to.<br /> The description field is an optional description of where the link points.', array('_TYPE_' => $type)));
-    $form .= form_checkbox(t('I need more _TYPE_ links.', array('_TYPE_' => $type)), 'phptemplate_' . $type . '_links_more', 1, FALSE, t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type)));
-
-  }
-  return $form;
+function phptemplate_theme($existing, $type, $theme, $path) {
+  $templates = drupal_find_theme_functions($existing, array($theme));
+  $templates += drupal_find_theme_templates($existing, '.tpl.php', $path);
+  return $templates;
 }
 
 /**
- * Prepare the values passed to the theme_page function to be passed
- * into a pluggable template engine.
+ * Implements hook_extension().
  */
-function phptemplate_page($content) {
-  global $node_cache;
-  /* Set title and breadcrumb to declared values */
-
-  if (file_exists(path_to_theme() . '/favicon.ico')) {
-    drupal_set_html_head("<link rel=\"shortcut icon\" href=\"" . path_to_theme() . "/favicon.ico\" />\n");
-  }
-
-  if ($_GET['q'] == variable_get('site_frontpage', 'node')) {
-    $mission = theme_get_setting('mission');
-    $frontpage = true;
-  }
-
-  $links['primary'] = array();
-  $links['secondary'] = array();
-
-  foreach (array('primary', 'secondary') as $type) {
-    //Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format.
-    $value = variable_get('phptemplate_' . $type . '_links', array());
-
-    //Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
-    $count = variable_get('phptemplate_' . $type . '_link_count', 5);
-    $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']);
-
-    if (theme_get_setting('toggle_' . $type . '_links')) {
-      for ($i =0; $i < $count; $i++) {
-        unset($attributes);
-        if (!empty($value['text'][$i])) {
-          if (!empty($value['description'][$i])) {
-            $attributes['title'] = $value['description'][$i];
-          }
-          $text = $value['text'][$i];
-          $link = $value['link'][$i];
-          if (substr($link, 0, 4) == 'http') {
-            $links[$type][] = '<a href="'. $link .'"'. drupal_attributes($attributes) .'>'. $text .'</a>';
-          }
-          else {
-            $links[$type][] = l($text, $link, $attributes);
-          }
-        }
-      }
-    }
-  }
-
-  /**
-  * Populate sidebars.
-  */
-  $layout = "none";
-  global $sidebar_indicator;
-  /**
-   * Sidebar_indicator tells the block counting code to count sidebars seperately.
-   */
-  $sidebar_indicator = 'left';
-  $sidebar_left = theme("blocks", "left");
-  if ($sidebar_left != "") {
-    $layout = "left";
-  }
-
-  $sidebar_indicator = 'right';
-  $sidebar_right = theme("blocks", "right");
-  if ($sidebar_right != "") {
-    $layout = ($layout == "left") ? "both" : "right";
-  }
-  $sidebar_indicator = null;
-
-  $vars = array(
-    'head_title'          => (drupal_get_title() ? strip_tags(drupal_get_title()) .' | '. variable_get('site_name', 'drupal') : variable_get('site_name', 'drupal') .' | '. variable_get('site_slogan', '')),
-    'language'            => $GLOBALS['locale'],
-    'site'                => variable_get('site_name', 'drupal'),
-    'head'                => drupal_get_html_head(),
-    'onload_attributes'   => theme('onload_attribute'),
-    'logo'                => theme_get_setting('logo'),
-    'site_name'           => (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : ''),
-    'site_slogan'         => (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : ''),
-    'search_box'          => theme_get_setting('toggle_search'),
-    'search_url'          => url('search'),
-    'search_button_text'  => t('search'),
-    'search_description'  => t('Enter the terms you wish to search for.'),
-    'title'               => drupal_get_title(),
-    'primary_links'       => $links['primary'],
-    'secondary_links'     => $links['secondary'],
-    'breadcrumb'          => theme('breadcrumb', drupal_get_breadcrumb()),
-    'tabs'                => theme('menu_local_tasks'),
-    'messages'            => theme('status_messages'),
-    'layout'              => $layout,
-    'help'                => theme('help'),
-    'styles'              => theme_get_styles(),
-    'mission'             => $mission,
-    'sidebar_left'        => $sidebar_left,
-    'content'             => '<!-- begin content -->' . $content . '<!-- end content -->',
-    'sidebar_right'       => $sidebar_right,
-    'footer_message'      => variable_get('site_footer', FALSE),
-    'closure'             => theme('closure')
-  );
-
-  /**
-   * Pass the node object to the page template on node views.
-   */
-  if (sizeof($node_cache) == 1) {
-    $vars['node'] = $node_cache[0];
-  }
-
-  return _phptemplate_callback('page', $vars);
-}
-
-/**
- * Prepare the values passed to the theme_node function to be passed
- * into a pluggable template engine.
- */
-function phptemplate_node($node, $main = 0, $page = 0) {
-  global $node_cache;
-  $node_cache[] = $node;
-
-  if (module_exist('taxonomy')) {
-    $taxonomy = taxonomy_link('taxonomy terms', $node);
-  }
-  else {
-    $taxonomy = array();
-  }
-
-  $vars = array(
-      'title'          => check_plain($node->title),
-      'node_url'       => url('node/' . $node->nid),
-      'terms'          => theme('links',$taxonomy),
-      'name'           => format_name($node),
-      'date'           => format_date($node->created),
-      'sticky'         => $node->sticky,
-      'picture'        => theme_get_setting('toggle_node_user_picture') ? theme('user_picture', $node) : '',
-      'content'        => ($main && $node->teaser) ? $node->teaser : $node->body,
-      'links'          => $node->links ? theme('links', $node->links) : '',
-      'mission'        => $mission,
-      'page'           => $page,
-      'taxonomy'       => $taxonomy,
-
-    /* Lastly , pass the actual node to allow more customization */
-      'node'           => $node,
-      'main'           => $main,
-      'page'           => $page
-    );
-
-  // Display info only on certain node types.
-  if (theme_get_setting('toggle_node_info_' . $node->type)) {
-    $vars['submitted'] =  t('Submitted by %a on %b.', array('%a' => format_name($node), '%b' => format_date($node->created)));
-  }
-
-  return _phptemplate_callback('node', $vars, 'node-' . $node->type);
+function phptemplate_extension() {
+  return '.tpl.php';
 }
 
 /**
- * Prepare the values passed to the theme_comment function to be passed
- * into a pluggable template engine.
- */
-function phptemplate_comment($comment, $links = 0) {
-  return _phptemplate_callback('comment', array(
-    'new'       => $comment->new ? t('new') : '',
-    'comment'   => $comment,
-    'submitted' => t('Submitted by %a on %b.',
-                      array('%a' => format_name($comment),
-                            '%b' => format_date($comment->timestamp))),
-    'title'     => l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid"),
-
-    'picture'   => theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', $comment) : '',
-    'links'     => $links,
-    'content'   => $comment->comment,
-    'author'    => format_name($comment),
-    'date'      => format_date($comment->timestamp)
-  ));
-}
-
-/**
- * Prepare the values passed to the theme_block function to be passed
- * into a pluggable template engine.
+ * Implements hook_render_template().
+ *
+ * Renders a system default template, which is essentially a PHP template.
+ *
+ * @param $template_file
+ *   The filename of the template to render.
+ * @param $variables
+ *   A keyed array of variables that will appear in the output.
+ *
+ * @return
+ *   The output generated by the template.
  */
-function phptemplate_block($block) {
-  return _phptemplate_callback('block', array('block' => $block));
-}
+function phptemplate_render_template($template_file, $variables) {
+  // Extract the variables to a local namespace
+  extract($variables, EXTR_SKIP);
 
-/**
- * Prepare the values passed to the theme_box function to be passed
- * into a pluggable template engine.
- */
-function phptemplate_box($title, $content, $region = 'main') {
-  return _phptemplate_callback('box', array(
-    'title'   =>   $title,
-    'content' =>   $content,
-    'region'  =>   $region
-  ));
-}
+  // Start output buffering
+  ob_start();
 
-/**
- * Default callback for PHPTemplate.
- */
-function _phptemplate_default($hook, $vars, $file = null) {
-  if ($file && file_exists(path_to_theme() . "/$file.tpl.php")) {
-    $file = path_to_theme() . "/$file.tpl.php";
-  }
-  else {
-    if (file_exists(path_to_theme() . "/$hook.tpl.php")) {
-      $file = path_to_theme() . "/$hook.tpl.php";
-    }
-    else {
-      if (in_array($hook, array('node', 'block', 'box', 'comment'))) {
-        $file = "themes/engines/phptemplate/$hook.tpl.php";
-      }
-      else {
-        $vars['hook'] = $hook;
-        watchdog('error', 'PHPTemplate was instructed to override the  ' . $hook . ' theme function, but no valid template file was found.');
-        $file = "themes/engines/phptemplate/default.tpl.php";
-      }
-    }
-  }
+  // Include the template file
+  include \Drupal::root() . '/' . $template_file;
 
-  if ($file) {
-    $phptemplate = new Template(dirname($file));
-    $phptemplate->set_vars($vars);
-    return $phptemplate->fetch(basename($file));
-  }
+  // End buffering and return its contents
+  return ob_get_clean();
 }
 
-?>
diff --git a/phptemplate.info.yml b/phptemplate.info.yml
new file mode 100644
index 0000000..1b51209
--- /dev/null
+++ b/phptemplate.info.yml
@@ -0,0 +1,6 @@
+type: theme_engine
+name: PHP template
+core: 8.x
+version: VERSION
+package: Core
+
diff --git a/readme.txt b/readme.txt
deleted file mode 100644
index bf9069d..0000000
--- a/readme.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-********************************************************************
-                D R U P A L   THEME  ENGINE                     
-********************************************************************
-Name: phptemplate
-Author: Adrian Rossouw
-Email: phptemplate at daemon dot co dot za
-
-********************************************************************
-DESCRIPTION:
-
-This is a theme engine for Drupal 4.5.0, which allows the use
-of templates written in pure PHP. This engine is a complete
-rewrite, and refactoring of the popular PHPTemplate theme 
-for Drupal 4.4.0.
-
-This theme uses no external templating engine, to allow for 
-remarkably robust templates without needing to modify the
-engine.
-
-PHPTemplate is being used as the basis for many of the largest
-Drupal sites, such as Spreadfirefox.com and Drupal.org itself.
-It is also the standard theme engine for Civicspace, although 
-that might change with the 1.x releases.
-
-The proto-template for PHPTemplate is box_grey, by Adrian Simmons
-and it can be found on Drupal.org. Additionally, the default
-template from the PHPTemplate theme in Drupal 4.4.0 is now called
-cleanslate, and is available in the same place..
-
-For more information on the reasons for not using a template engine
-please see the following article:
-http://www.phppatterns.com/index.php/article/articleview/4/1/1/
-
-More complete documentation can be found on the Bryght public Wiki
-at http://dev.bryght.com , and a subset of that documentation is 
-also available in the Drupal handbook (http://drupal.org/node/11810).
-
-********************************************************************
-SYSTEM REQUIREMENTS:
-
-Drupal: Drupal 4.5.0 , or Latest CVS.
-
-********************************************************************
-INSTALLATION:
-
-Extract the phptemplate.tar.bz2 file into your themes/engines directory.
-
-********************************************************************
-SPECIAL THANKS :
-
-Adrinux, Berkes, Boris Mann and Walkah for all the support during the 
-development process.
diff --git a/template.php b/template.php
deleted file mode 100644
index 5f6a9dc..0000000
--- a/template.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * Copyright (c) 2003 Brian E. Lozier (brian@massassi.net)
- *
- * set_vars() method contributed by Ricardo Garcia (Thanks!)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-class Template {
-	var $vars; /// Holds all the template variables
-	var $path; /// Path to the templates
-
-	/**
-	 * Constructor
-	 *
-	 * @param string $path the path to the templates
-	 *
-	 * @return void
-	 */
-	function Template($path = null) {
-		$this->path = $path;
-		$this->vars = array();
-	}
-
-	/**
-	 * Set the path to the template files.
-	 *
-	 * @param string $path path to template files
-	 *
-	 * @return void
-	 */
-	function set_path($path) {
-		$this->path = $path;
-	}
-
-	/**
-	 * Set a template variable.
-	 *
-	 * @param string $name name of the variable to set
-	 * @param mixed $value the value of the variable
-	 *
-	 * @return void
-	 */
-	function set($name, $value) {
-		$this->vars[$name] = $value;
-	}
-
-	/**
-	 * Set a bunch of variables at once using an associative array.
-	 *
-	 * @param array $vars array of vars to set
-	 * @param bool $clear whether to completely overwrite the existing vars
-	 *
-	 * @return void
-	 */
-	function set_vars($vars, $clear = false) {
-		if($clear) {
-			$this->vars = $vars;
-		}
-		else {
-			if(is_array($vars)) $this->vars = array_merge($this->vars, $vars);
-		}
-	}
-
-	/**
-	 * Open, parse, and return the template file.
-	 *
-	 * @param string string the template file name
-	 *
-	 * @return string
-	 */
-	function fetch($file) {
-		extract($this->vars);          // Extract the vars to local namespace
-		ob_start();                    // Start output buffering
-		include($this->path . "/$file");  // Include the file
-		$contents = ob_get_contents(); // Get the contents of the buffer
-		ob_end_clean();                // End buffering and discard
-		return $contents;              // Return the contents
-	}
-}
-?>
