0

I am working on a Drupal site. My issue is that when a link is created either by using the url() or the base_path variable, it works OK on local development environment. But when the very same code is put on the server, the URL prepends node string in the path .

E.g. the path is <drupal site>/latestnews. The generated path is <drupal site>/node/latestnode and when clicked, it shows the page not found error. However I would like to mention that the links work fine (i.e generate correct path) when clicked from the home page.

Any help would be appreciated. If it can help, am using Pantheon hosting for testing.

UPDATE

menu link generation code is as under. (the code can show my proficiency in drupal :) )

function GetMainMenuItems()
{
    $menu = menu_tree("main-menu");

    $keys = array_keys($menu);

    $count = count($keys);

    unset($keys[$count-1]);
    unset($keys[$count-2]);

    $items = array();

    foreach ($keys as $key) {
        $temp = array(
            'title' => $menu[$key]["#title"],
            'url' =>   url($menu[$key]["#title"])
        );
        $items[] = $temp;
    }
    return $items;
}
  • Where are you creating the link? in tpl.php or a textfield? does l('linktext','latestnews') work? – Marcel Jan 6 '14 at 18:35
  • 1
    can you put in some of your actual code? and, do you have the default front page set identically (eg, check admin/config/system/site-information if D7, admin/settings/site-information if D6) – Jimajamma Jan 6 '14 at 18:45
  • @Marcel the link currently is being generated for menu items in menu.php file (which is later included in template files) – Abdul Ali Jan 6 '14 at 19:12
  • Your links are relative, thats why they work @ homepage and not at other pages which have node in it. If you would go to /contact and click such a link you would go to /contact/latestnews. You should prepend a '/' to your generated links. (more info can be found @ hook_menu() @ drupal.org.) – Marcel Jan 7 '14 at 10:29
  • @Marcel the link is being generated by the url function of the drupal and as far as i could understand it, this was the standard way to pass the link parameter to this function – Abdul Ali Jan 8 '14 at 17:57
1

the issue (for the current scenario) turned out to be hardcoded link in the page.tpl.php file. the front page was working ok as it had its own custom template but other pages were using the page.tpl template for rendering the links.

seems that sometimes small issues goes undetected. :) . just leaving this answer so that someone else may also look into such a possibility in their case.

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.