Jump to content

[Solved] Navigation breaks on form template after using relative paths


ryanC
 Share

Recommended Posts

Hi, I am testing my site on a local machine. I am having an issue with navigation links being broken on my form template after changing the link paths from direct to relative:

I have two templates, “main-template” and “form-template”. Those templates include the same header file:

<?php include("includes/header.inc.php"); ?>

That  file contains the site navigation. Originally, the links were direct paths: 

<a href=“/site-name/pagename”>Page with direct path</a>

But I changed them to relative paths:

<a href=“../../pagename”>Page with relative path</a>

So far, so good. Everything works on the site except the navigation on the form page breaks. Clicking on those links wants to take me back to my root htdocs folder.  I think it  might have something to do with the form not being able to post to a template file, so it posts to itself instead. 

I have found a temporary work around, which is create a NEW header include file that only the form template uses. If I give those links shortened relative paths:
<a href="../pagename">

It all works, except I now have two unique navigation menus I have to keep track of, when I would rather have just one header file for the entire site. 

Any ideas on how I can keep the same header file with the main-template and form-template? Thanks!

Link to comment
Share on other sites

10 minutes ago, ryanC said:

Any ideas on how I can keep the same header file with the main-template and form-template? Thanks!

Don't use relative paths. They are an artifact of days long gone (at least in regular websites - there are use cases in routed app components) and they create more problems than they solve. If you worry what happens when you move a site to a deeper directory, use PHP to prefix your links with $config->urls->root.

  • Like 3
Link to comment
Share on other sites

Thanks BitPoet, man I already had it set up that way originally. I don't know why I changed it. My template already had:

<?php $myPath = $config->urls->templates;?>

at the top, and my links were already

"<a href="/site-name/pagename">

 So now it works again by reverting. 

Not sure why I changed it... I guess I just didn't comprehend what that <?php $myPath = $config->urls->templates;?> was doing... means my site name itself can be anything I want. Thanks!

  • Like 1
Link to comment
Share on other sites

22 hours ago, ryanC said:

<a href=“/site-name/pagename”>Page with direct path</a>

How big is your navigation? If you've got a huge flyout nav with 4 levels, you should use soma's MarkupSimpleNavigation module or something similar.

Maybe your site isn't multilang, but using the page-slug will not go so well if you ever decide to add another language to your site.

Why not simply use

<a href="<?=$pages->get(123)->url?>"><?=$pages->get(123)->title?></a>

 instead?

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...