0

I have a custom theme and a custom module. The module shows users. Every user has its specific image (that can be uploaded, changed). The location/name of this file is in the database.

I have an template with specific layout for that page: page--uspage.tpl.php In this page, I need the location from the database when I access uspage.

$items['uspages'] = array(
    'title' => 'User pages', //page title
    'description' => 'User pages',
    'page callback' => 'show_uspages'
);

$items['uspage/%'] = array(
    'title' => 'User page',
    'description' => 'User page detail',
    'page callback' => 'show_uspage',
    'page arguments' => array(1),
    'access callback' => TRUE,
     'type' => MENU_CALLBACK,
);

I have a lot of other pages that doesn't need that. So I can't use preprocess_page.

What's the easiest and best way to pass an array with the backgroundinformation from the function show_uspage to page--uspage.tpl.php ?

0

Short but painfully: there is no way to achieve that. The page.tpl expects that your part of the code is a renderable array or HTML output fully generated in your page callback show_uspage(). Your part of the code is injected into the $variables of hook_preprocess_page() where ever the content block is placed in region settings for your theme. Your page callbacks really just handles the part of the output where the content block is placed. You can not store any data from your page callback for later use in theme layer or send the data by any mean to the page preprocess function or any other theming function for the page.tpl.

The only way would be to use hook_preprocess_page() and to add any data here again. You must use this hook even when you add data just for a specific page - you just need to assure to do that in this case and not on every page. Maybe by checking on which path the user is (like if(current_path == 'uspages')).

Another way would be to store the data in session in re-use it in hook_preprocess_page.

| improve this answer | |
0

You can try to use Context module It provides a centralized set of API functions for setting and retrieving a static cache. You can set own variable in one module and retrieve in another. This is interesting article about this. https://www.phase2technology.com/blog/passing-variables-between-different-drupal-hooks-using-context-api/

| improve this answer | |
  • I will check this.. – Finduilas Mar 9 '17 at 6:56

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.