Blog Post Icon

Drupal Development : Make a page template for dynamic page requests


Drupal is a fantastic content management system with an even more fantastic development community.

Recently through our own Drupal development projects, we came across a scenario that required the processing of dynamic (i.e. “Wildcard”) page requests to the same drupal page template. If I’ve lost you already , don’t worry! All we are trying to do is ensure the following page request scenarios are served by the same page template : -> page–page1–wildcard.tpl.php -> page–page1–wildcard.tpl.php

You can see in the two above scenarios, that the “page1” root request URI is the same, but the subsequent URI requests , “randomrequest1” and “randomrequest2” are different. What happens if you want to use the same page template for both random requests? Easy, you implement a check in the preprocess page hook in template.php!

In your drupal theme, you will have a file called template.php. This is where all the pre, post and other processing of variables are handled. This is where you can define a logical check that associates a page template with a particular request. There is technically a few ways you can accomplish this task, but the way we’ll show you is with the theme_preprocess_page function.

Here is the code that is used to break the request URI , analyze it, and associate a page template if the condition matches :

$path = request_path();
$fixed_path = explode('/', $path);
if (count($fixed_path) == 2 && $fixed_path[0] == 'page1')
$vars['theme_hook_suggestions'][] = 'page__page1__wildcard';

What does the above code do? It takes the request path, breaks up each request into an array, if the first URI is “page1”, then assign the respective page template. In our scenario, we were building a page that displays a user “profile” without having to create a separate drupal page for each user and assigning a page or node template respectively. What if you had 100 or 1,000 users? That would be tedious!

If a user enters ,then it will display our wildcard page template! Great! In the page template itself , we would be doing a few more checks and then displaying the user profile. I’ll save that for another post šŸ™‚

At Shift8, we cater to all sorts of businesses in and around Toronto from small, medium, large and enterprise projects. We are comfortable adapting to your existing processes and try our best to compliment communication and collaboration to the point where every step of the way is as efficient as possible.

Our projects are typically broken into 5 or 6 key “milestones” which focus heavily on the design collaboration in the early stages. We mock-up any interactive or unique page within your new website so that you get a clear picture of exactly how your design vision will be translated into a functional website.

Using tools like Basecamp and Redpen, we try to make the process simple yet fun and effective. We will revise your vision as many times as necessary until you are 100% happy, before moving to the functional, content integration and development phases of the project.

For the projects that are more development heavy, we make sure a considerable amount of effort is spent in the preliminary stages of project planning. We strongly believe that full transparency with a project development plan ensures that expectations are met on both sides between us and the client. We want to ensure that the project is broken into intelligent phases with accurate budgetary and timeline breakdowns.

Approved design mock-ups get translated into a browse-ready project site where we revise again and again until you are satisfied. Client satisfaction is our lifeblood and main motivation. We aren’t happy until you are.

Need Web Design?

Fill out the form to get a free consultation.

shift8 web toronto – 416-479-0685
203A-116 geary ave. toronto, on M6H 4H1, Canada
Ā© 2024. All Rights Reserved by Star Dot Hosting Inc.

contact us
phone: 416-479-0685
toll free: 1-866-932-9083 (press 1)

Shift8 Logo