Jump to content

Recommended Posts

Posted

simple question: how to link to a side, which is not shown in the navigation, but in footer.

Page 'disclaimer' is in the tree under root, is hidden, but published. Normally I woud do it this way:

<a href="../disclaimer">Disclaimer</a>

but under the home (root) the url points one step higher.

Didn't found any tutorial, cheatsheets are a big collection of developer/guru speaking, search in forum not helpful.. ???  Is that so difficult??

Posted

Not difficult at all.

The way you are doing it, the two dots are pointing one directory up, wish means that the browser is looking for a page that is at the same level then root. If you would do this for example:
 

<a href="/disclaimer">Disclaimer</a>


...it would work on the root, but not on the other pages.

To fix it, you have two options. On a non dynamic site, the option would be having an absolute link instead of a relative link:
 

<a href="http://www.yoursite.com/disclaimer">Disclaimer</a>

In PW you can do something that will allow you to change the domain of the website without breaking the link:
 

<a href="<?= $pages->get('/disclaimer/')->url ?>">Disclaimer</a>

edit: see soma's correction below for a more correct and accurate answer ↴

Posted

Not difficult at all.

The way you are doing it, the two dots are pointing one directory up, wish means that the browser is looking for a page that is at the same level then root. If you would do this for example:

<a href="/disclaimer">Disclaimer</a>

...it would work on the root, but not on the other pages.

To fix it, you have two options. On a non dynamic site, the option would be having an absolute link instead of a relative link:

Sorry to correct you here diogo, but <a href="/disclaimer">Disclaimer</a> works for all levels as it's absolute starting from "/" root. Still better in PW is <a href="/disclaimer/">Disclaimer</a> as it would do a redirect to add trailing slash which is default in PW.

You could also use id of the page, so even if you move the page it still get's the right url to the page.

<a href="<?= $pages->get(1023)->url ?>">Disclaimer</a>
 
Posted

thanks diogo/soma

hmm ok, I missed the ->url

<a href="<?= $pages->get('/disclaimer/')->url ?>">Disclaimer</a>

think, PW could get more fresh users with better helpful documentations in practical context.

Posted

http://processwire.com/api/cheatsheet/#page 5th entry in that list.

$page->url is something so basic and covered all over the place on processwire.com. It's all under API, as it's the only thing you need to know to build templates/pages

http://processwire.com/api/what/

http://processwire.com/api/templates/

http://processwire.com/api/variables/page/

http://processwire.com/tutorials/quick-start/navigation/

Or of course http://wiki.processwire.com/index.php/Main_Page.

If not, there's even a basic site when you install PW which also is something you want to study first when starting with PW and come ask question if you don't understand something here.

I think that's quite good and there's many people think PW has exceptional documentation for a OS project. For some strange reason we still have to figure out why some people think the opposite.

There's also the forum which has tons of examples (might use google search to search) and simple questions get answered here mostly immediately.

  • Like 3
Posted
I think that's quite good and there's many people think PW has exceptional documentation for a OS project. For some strange reason we still have to figure out why some people think the opposite.
 

This is absolutely true. I think most people just want to do their own stuff - which is totally understandable. But it would be better to study the planets, Joss, blog profile, skyscrapers profile and created the first site afterwards. One thing I had a hard time understanding is the modal stuff like $this->that->image->url. Those things are difficult to cover in any tutorial, but my experience is that you have to read between the lines. And suddenly you know it when you understand it.

Posted
Sorry to correct you here diogo

Thanks for correcting me soma. That was a basic error, I should be more careful.

There's also the forum which has tons of examples (might use google search to search)

shouldn't we make it obvious and just implement google search alongside the forum search?

  • Like 1
Posted

+1 for Google search as addition to the forum search.

I almost never find the thread or the answers searching for with the internal search :wacko:

Posted

Mostly repeating what's already been said. But if that disclaimer page is always going to be off the root, regardless of whether on your development or production server, the I would just do this:

<a href='/disclaimer/'>Disclaimer</a>

If the site may move around from one subdirectory to another (like between development and production, as is the case for me), then I'd do this:

<a href='<?=$config->urls->root?>disclaimer/'>Disclaimer</a> 

If you want to account for the possibility that the disclaimer page may move, then you'd do this (where 123 is the ID of the disclaimer page): 

<a href='<?=$pages->get(123)->url?>'>Disclaimer</a>

Though note that you are then talking about more overhead in this last example, relative to the first two. So it's rare that I do this, unless it's a page that needs to move often (don't think I've run into that situation). 

  • Like 1
  • 1 year later...
Posted

Since I would think it would add a db query every time you look up a page id, I think I am going to do the $config->urls->root method in most cases as well!

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
  • Recently Browsing   0 members

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