Jump to content

charger

Members
  • Posts

    111
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by charger

  1. That's a good idea, however, I don't want automatic price conversion. Price politics is more about psychology than mathematics
  2. I don't now if this is already possible to build with one of the available modules/fieldtypes. I so far tried Table, PageTable, Repeater and Multiplier but couldn't get them work exactly as I want. I'm looking for a way to create a matrix/table that uses the children of two pages to build the row and column headers. In my case (an online shop), I want it to take the children of the page product variants and the children of the page currencies. In the end, it should render a matrix/table, where I can enter a fixed price for every variant in every currency. Has anyone ever done something similar? Is there a fieldtype for this?
  3. Would you mind sharing your solution? I'm in the same boat and don't know exactly how to achieve this with the fieldtype concat. What I'd like to achieve is an anchor like this: #target_name However, the field name has an output of "name", not the actual page name. The same happens with these fields as well: id, path, url, template
  4. Ok, I've found a minor bug: If the page is open simultaneously in two browser tabs, then change change the language from english (/) to german (/de/) in the first tab, then reload the second tab, everything works fine and the second tab is redirected to the german page as well. However, if I switch back to english on the first tab and then again reload the second tab (which is still on the german page), I get a "too many redirects" error. Any idea why this happens?
  5. I tried to build upon Ryan's code above and to add the possibility of setting a cookie, so that a users language selection is remembered. Here's what I came up with. /site/templates/_init.php: if(isset($_COOKIE["user_language"])) { $language = $_COOKIE["user_language"]; } else { $name = $sanitizer->pageName(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)); if($name == "en") $name = "default"; // because default language cannot be renamed to en $language = $languages->get($name); setcookie("user_language", $language, time()+3600*24*365, "/"); } if($language != $user->language) { $url = substr($pages->get('/')->httpUrl, 0, -1) . $page->localUrl($language); $session->redirect($url); } Then, I've added an event handler to the language select: function createCookie(name, value, days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } else { expires = ""; } document.cookie = encodeURI(name) + "=" + encodeURI(value) + expires + "; path=/"; } $(".select-language a").click(function() { var value = $(this).attr("data-language"); createCookie("user_language", value, 365); }); The language select itself within the template file looks like this (source): $savedLanguage = $user->language; foreach($languages as $language) { if(!$page->viewable($language)) continue; $user->language = $language; if($language->isDefault()){$out = "en";} else {$out = $language->name;} echo "<a href='{$page->url}' data-language='{$language->id}'>{$out}</a>"; } $user->language = $savedLanguage; Everything seems to work so far. But as I just began to work with processwire; does anyone of the more experienced guys see a potential problem with this solution? Ryan also mentioned possible problems with caching in his post above. Is there a way around this? Could it help if I run this code only on the startpage (instead of _init.php)?
×
×
  • Create New...