0

I want to create a page that render a template (.tpl) file with this:

hook_menu

    $items['news'] = array(
    'title callback' => 'check_plain',
    'title arguments' => array('News'),
    'page callback' => 'theme',
    'page arguments' => array('news', array()),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
);

hook theme

$items['news'] = array(
    'template' => 'templates/news',
);

All works well if i go to www.mydomain/news

But if i go to www.mydomain/news/aaaaa (that is a non existing page) i will see again the template page and not a 404 error page, why?

Is this a normal d7 behaviors and i need to fix this in a callback function? ...or i need to check into other code/modules that cause this bug ?

2

Yes, that's expected behaviour. From the hook_menu() docs:

If there is no other registered path that fits the requested path better, any further path components are passed to the callback function.

Here's the bug report that was closed as "works as designed":

https://www.drupal.org/node/1091068

0

You can use a wildcard in your hook menu item like this: $items['news/%']. But why you are using theme function as a page callback? How do you handle loading news?

Please review this link: create .tpl file for a single custom page then you can load your news by EntityFieldQuery.

Your Answer

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