2

Is there a way to make page.tpl.php and page--front.tpl.php share the same template base?

If any of you are familiar with the Twig templating engine, You can define blocks with {% block content %}Node Content{% endblock %} and then do something like:

{% extends 'page.html.twig' %}
{% block content %}Home Page Stuff{% endblock %}

Does PHPTemplate have anything equivalent? I tried using PHP's include() but it doesn't work.

3 Answers 3

2

The theme system works by looking for templates that are a precise matches for the current path and then falling back to looking for less and less precise pages.

If you

  1. delete your page--front.tpl.php
  2. clear the cache

Then phptemplate should use page.tpl.php for your front page.

0

Make a file, fe called page.shared.inc.php enter your shared code (html/php).

Then add the following to the page.tpl.php and page--front.tpl.php

This should work.

0

PHP include() does work, and I bet I know why you're having trouble. Relative paths in include() are relative to the original script, not the file being included. So if you put include('thingy.php'), it's probably looking for it in the Drupal root directory next to index.php, not in your theme.

PHP's __DIR__ constant returns the path to the current PHP file's directory, so if you do something like

<?php include(__DIR__ . '/thingy.php');

it ought to work. (Do remember to lead your path with a slash, as __DIR__ does not end with one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.