pwired Posted December 22, 2015 Share Posted December 22, 2015 Hi,I am working on a main navigation menu (start, faq, contact) and a sub navigation menu (para ipad, blackbox, mando a distancia) See screenshot aboveWhen I select a language in the top right corner all menu items appear in their language correctly. So far so good.Now, when I then click on a menu item, it has to open a page in the current language.When I use this for example it will not open the contact page in the current language but in the default language (english) and also all menu items revert back to the default language (english) <li id="contact"><a href="/contact/" title=""><?php echo $contact ?></a></li> After some puzzeling I came up with this and now it opens the contact page in the current language and the menu items no longer revert back to the default language. So far so good. echo "<li>" . "<a href=" . '"' . $pages->get('/contact/')->url . '"' . ">" . $contact . "</a>" . "</li>"; It works, but when I look at that line of code it looks a bit over the top so I am wondering if there isn't a better or compacter way of doing this. Link to comment Share on other sites More sharing options...
diogo Posted December 22, 2015 Share Posted December 22, 2015 After some puzzeling you found out how to do a navigation with PW https://github.com/ryancramerdesign/ProcessWire/blob/dev/site-beginner/templates/_head.php#L28 2 Link to comment Share on other sites More sharing options...
BitPoet Posted December 22, 2015 Share Posted December 22, 2015 Correct me if I understood wrong. This looks like you're assembling the navigation menus manually. Hardcoding an absolute path for a navigation entry will of course point to the page in its default language if you don't specify a prefix for a different language. In that case, fetching the page in question and assembling the link from its properties is the way to go. Perhaps you could add a function that abstracts away the repeated verbosity. <?= navItem('/contact/') ?> <?= navItem('/faq/') ?> and further down (or in _init.php or such) add your function: function navItem($path) { $pg = wire('pages')->get($path); return "<li><a href='" . $pg->url . "'>" . $pg->title . "</a></li>"; } 1 Link to comment Share on other sites More sharing options...
pwired Posted December 22, 2015 Author Share Posted December 22, 2015 This is the first time I had to do both a multi language navigation banner plus a sub navigation and somehow the sub navigation part got me tricked. You guys are good at this: echo "<li class='current'><a href='$child->url'>$child->title</a></li>"; that easy Since I am really into delayed output lately (prepend _init.php append _main.php) I also like the function navItem approach Thanks for your replies, I am back on track. Link to comment Share on other sites More sharing options...
clsource Posted December 23, 2015 Share Posted December 23, 2015 It's easy $page->localUrl($user->language); $page->localHttpUrl($user->language); it will output the correct url that belongs to the user language 1 Link to comment Share on other sites More sharing options...
pwired Posted December 24, 2015 Author Share Posted December 24, 2015 What is shown in the link https://github.com/ryancramerdesign/ProcessWire/blob/dev/site-beginner/templates/_head.php#L28 is a for each loop that outputs all children and use the title as a visible word to click on. But this is not always wanted as in my case. I want some children (not all of them) as links in a sub navigation menu and I don't want to use the titles of them as the visible words to click on, but other relevant word combinations. I would not know how to change this for each loop in such a way that it outputs or filters out only the children that I wanted and the words that I wanted to click on. Hence the solution I came up with. Maybe hanna code could make it translate and look more compact. Link to comment Share on other sites More sharing options...
Recommended Posts