Hardcode block and add parent page in multilingual autonav
Permalink
Hello
1) How do I hardcode a block? I'm trying to hardcode the built in language switcher block, so that the client cannot accidentally remove it. Just like I always hardcode navigation, so I thought I could use the same procedure as the autonav:
The block does get rendered, but it's not working properly. When I switch language in the dropdown nothing happens. If I insert the language switch block via the interface it works fine.
2) What is the best way to display both the parent page and it's children in an autonav on a multilingual website? I wan't the first nav item to be a link to the frontpage, "home", which is the parent.
Parent page
- Children
- Children
- Children
I know 2 hacky solutions, but I wonder what's the best, dynamic and clean way to do it.
- I could add an external link in the sitemap, but I don't like that approach because of absolute URL's and noise that litters the sitemap.
- I can hardcode a home button in a view.php override for autonav with an if/else statement depending on Localization::activeLanguage() I don't like this either, because it's not dynamic if the client want's to add a new language, and it's a super ugly hack.
Thanks for your time
Best regards
Jeppe
1) How do I hardcode a block? I'm trying to hardcode the built in language switcher block, so that the client cannot accidentally remove it. Just like I always hardcode navigation, so I thought I could use the same procedure as the autonav:
$bt = BlockType::getByHandle('switch_language'); $bt->render('view');
The block does get rendered, but it's not working properly. When I switch language in the dropdown nothing happens. If I insert the language switch block via the interface it works fine.
2) What is the best way to display both the parent page and it's children in an autonav on a multilingual website? I wan't the first nav item to be a link to the frontpage, "home", which is the parent.
Parent page
- Children
- Children
- Children
I know 2 hacky solutions, but I wonder what's the best, dynamic and clean way to do it.
- I could add an external link in the sitemap, but I don't like that approach because of absolute URL's and noise that litters the sitemap.
- I can hardcode a home button in a view.php override for autonav with an if/else statement depending on Localization::activeLanguage() I don't like this either, because it's not dynamic if the client want's to add a new language, and it's a super ugly hack.
Thanks for your time
Best regards
Jeppe
It is generally not recommended to hard code blocks, especially the Auto-Nav block. Hard coded blocks prevent full page caching which can hurt site performance. An alternative is setting permissions on the block.