Problem with "replace_link_with_first_in_nav"
PermalinkI added "replace_link_with_first_in_nav" attribute for "EN" folder in my sitemap :
Home
- EN
-- page1
-- page2
So when i click on EN i am redirected to "page1". ok.
But i write in address bar "http://www.mysite.com/en", I'm not redirect to "page1"...
An idea ?
Thanks
Thanks for your answer.
It's a good idea thanks.
Actually, to do that, I have created a page type which can be used by a page and do redirect link to his firschild if exist, else 404 error.
What do you think about that ?
The overhead you generate by putting this in header.php isn't huge and makes things easier.
If you use a page type, I recommend to delete the attribute. If the page type knows that the sub page is the one where the actual content is located, there's no need for an attribute.
By doing this, you'd have a simple solutions as well. I only recommend to use the attribute or a page type but not both at the same time.
However, if you want to use the page type only you'd have to modify autonav as well which is why I probably keep using the attribute in header.php..
Uhh so many options (: At the end, whatever you do, I guess it works ;-)
I called the page type "Category", and implemented the redirect in the page type's controller like this:
// File: /controllers/page_types/category.php class CategoryPageTypeController extends Controller { public function on_start() { $subPage = $this->c->getFirstChild(); if ( $subPage instanceof Page ) { $nh = Loader::helper('navigation'); $url = $nh->getLinkToCollection($subPage); // This may happen if there are no children in the Category. } else { $url = '/'; } header( 'Location: ' . $url ); exit;
I've toyed around with the idea of using an optional attribute to let the user specify where to redirect. Comments and suggestions are welcome.
For the option which let user to choose page redirection, i have post in Beta Crew section :http://www.concrete5.org/developers/beta/beta_bitching/page-redirec...
Most people probably don't care, but redirects should be avoided. It's also the reason why there should be a slash at the end of a URL if it's not a file..
replace_link_with_first_in_nav is only used in autonav to create links to sub pages.
If you want to redirect to a subpage if you directly call a page you have to add some more code. header.php in your theme works for example.
Something like this might work..
Todo:
- Add status code
- Make sure it works in a recursion to support sub-sub-pages
etc.