Jump to content

Gadgetto

Members
  • Posts

    394
  • Joined

  • Last visited

  • Days Won

    12

Everything posted by Gadgetto

  1. Hmm.. 19 posts and COMMUNITY REPUTATION = excellent and still no edit feature enabled. I see someone is giving me likes ? so maybe I'll be able to update my tutorial soon! Thanks whoever is "liking" me! ?
  2. Hello, is it possible to configure CKEditor to have syntax highlighting enabled in Source and/or Sourcedialog? Coming from MODX i had this feature enabled and now I'm trying to find a solution for PW too. I'd like to have both the WysiWyg Editor and the Source editor with syntax highlighting enabled in on field. Andy plugins to achieve this? Greetings, Martin
  3. I have an update ready for this tutorial! As soon as I can edit my posts I will put the changes online!
  4. I'd definitely buy a ProcessWire book! eBook version should be included.
  5. Good objections that I had never thought of before! If I only could edit my post I‘d correct the tutorial...
  6. Here is the GitHub link to the flag-icon-css repo: https://github.com/lipis/flag-icon-css Don't use flags for language selectors as flags do not represent languages!
  7. Hello, I'm very new to ProcessWire but already fell in love with this CMS/CMF! I just finished my first small project and as I saw a lot of questions and different answers in this forum on how to set up a nice language switcher for your website, I decided to write my first tutorial. ---------- Please note: I rewrote this tutorial since I was made aware and learned that flags should not be used for language selectors! There are some threads here in the forum (and from external sources) where this question is discussed: https://processwire.com/talk/topic/13196-adding-image-field-to-language/ http://daily.unitedlanguagegroup.com/stories/editorials/inside-design-language-selector-no-flags https://processwire.com/talk/topic/16524-extending-languages-template/ http://www.flagsarenotlanguages.com/blog/why-flags-do-not-represent-language/ https://processwire.com/talk/topic/14241-language-names-and-utf8-page-names/ Thanks, @ottogal @bernhard @jmartsch @kongondo an all others for your hints! ---------- TUTORIAL - Set up a nice language switcher for your website - here we go: This will be the desired result! Step 1) Setup at least 2 languages in your PW install. In my case it's German (default language) + English: Step 2) Add a custom field Type = Text Name = languagecode This will hold the ISO 639-1 two-letter language code for the respective language. The field is needed to provide a simple method for outputting the language code in your templates. Without this field, you will need to programmatically construct your two-letter language code output via PHP (at least for the default language, as ProcessWire doesn't allow to rename the default language and it will always be called default). Here is an overview for ISO 639-1 two-letter language codes: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes Step 3) Add this field to the system template: language. To achieve this, go to Setup / Templates and activate the filter Show system templates: Now you can add the previously created field languagecode to the language template. Step 4) Edit your languages and fill in the appropriate values. a) default (German) Name = default (this can't be changed and is read only) Title = Deutsch (in both language tabs! - this is important as your visitor should always see his language item ... in his language) languagecode = de b) english (English) Name = english Title = English (in both language tabs! - this is important as your visitor should always see his language item ... in his language) languagecode = en Step 5) Now we are ready to write our template output! As we already have the appropriate two-letter ISO language code (languagecode field), we can use this in our html lang property: <html lang="<?php echo $user->language->languagecode; ?>"> Also the rel alternate output in the html head is simple. Put the following code within your <head></head> area: <?php // Handle output of 'hreflang' link tags for multi-language (SEO!) foreach ($languages as $language) { if (!$page->viewable($language)) { continue; } // Get the http URL for this page in the given language $url = $page->localHttpUrl($language); // Get the language code using custom languagecode field $languagecode = $language->languagecode; echo PHP_EOL.'<link rel="alternate" hreflang="'.$languagecode.'" href="'.$url.'">'; } ?> In my sample I've used Boostrap 4 and the code below shows a complete navbar with our language switcher (BTW the language switcher will always be visible, even when the bootstrap navbar is collapsed): <nav id="mainnav" class="navbar navbar-expand-lg navbar-light px-4 px-md-5 sticky-top"> <a class="navbar-brand" href="<?php echo $config->urls->root; ?>"> <img src="<?php echo $config->urls->templates; ?>images/logo-rund-80x80.png" alt=""> Your Site Title </a> <ul class="navbar-nav ml-auto mr-3 mr-lg-0 order-lg-last d-none d-xs-custom-flex language-switcher" aria-label="<?php echo __('Sprache wechseln') ?>"> <?php echo '<li class="nav-item dropdown">'; // Construct the language prompt in the current user language $prompt = $user->language->title.' ('.strtoupper($user->language->languagecode).')'; // Current language = dropdown-toggle echo '<a class="nav-link dropdown-toggle" href="#languages" id="language-select" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'; echo '<span class="world-icon"></span><span class="sr-only">'._x('(aktuelle Sprache)', 'navigation').': </span> '.$prompt; echo '</a>'; echo '<div id="languages" class="dropdown-menu dropdown-menu-right" aria-labelledby="language-select">'; foreach ($languages as $language) { // Get the http URL for current page in the given language $url = $page->localHttpUrl($language); // Construct the language prompt in the given language $prompt = $language->title.' ('.strtoupper($language->languagecode).')'; // Next language item (except current language) if ($user->language->id != $language->id) { if (!$page->viewable($language)) { echo '<span class="dropdown-item disabled">'.$prompt.'</span>'; } else { echo '<a class="dropdown-item" href="'.$url.'">'.$prompt.'</a>'; } } } echo '</div>'; echo '</li>'; ?> </ul> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarMainMenu" aria-controls="navbarMainMenu" aria-expanded="false" aria-label="<?php echo __('Menü einblenden / ausblenden') ?>"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse my-3 my-lg-0" id="navbarMainMenu"> <ul class="navbar-nav mr-auto"> <?php // Top navigation consists of homepage and its visible children foreach ($homepage->and($homepage->children("template=main-page|news|contact-points")) as $item) { if ($item->id == $page->rootParent->id) { echo '<li class="nav-item active">'; echo '<a class="nav-link" href="'.$item->url.'">'.$item->title.'<span class="sr-only"> '._x('(aktuelle Seite)', 'navigation').'</span></a>'; echo '</li>'; } else { echo '<li class="nav-item">'; echo '<a class="nav-link" href="'.$item->url.'">'.$item->title.'</a>'; echo '</li>'; } } ?> </ul> </div> </nav> That's it! I hope you will like my tutorial and if there are any questions, critics or improvements please let me know! Thanks, Martin
  8. OK, thought something like that... Since I'm already in love with ProcessWire, it won't take long as I'll bombard the forum with my questions! ?
  9. Hello, I see other users have forum signatures below their posts. how can I prepare a signature too? Also I can't klick on "like" button. Do I need more reputation to have those features enabled? Greetings, Martin
  10. Forgot to say, problem happens on version 3.0.118. After removing this folder and running upgrade to 3.0.119 I couldn’t reproduce the issue.
  11. Same problem here! Removing the content of the /site/assets/cache/ProcessWireUpgrade folder wasn't enough. Needed to remove this folder completely.
  12. This (and selecting by id) seems to be the best answers for my question! Thank you @Zeka and all others for your help! I've heard before that the Processwire community is very helpful and friendly and I have to say that's absolutely true! I'm just trying to understand the basics of Processwire. Hence my seemingly pointless questions. I come from a different CMS (MODX) and it's a bit difficult to rethink at first. So I hope you'll also excuse my upcoming stupid questions... ? @bernhard Hey, I'm also from Austria - only 60 km from Vienna, in Mattersburg.
  13. @elabx Thank you for your extensive answer! But my question was about how to get a specific page when there are multiple languages. The name field wont work as it has different content for each language. Seems I need to uses the id field in this case (which doesn’t seem to be the best way).
  14. Getting the page by it's id was my first thought, but is this the best way? The id field isn't even visible in PW, only in browsers URL...
  15. @Zeka Thank you for jumping in again! Let's say I'd like to output the title field and the summary field from the "sample-page" (DE name -> "beispiel-seite") on the "home" page (maybe in a sidebar). How would I reference the content of these fields?
  16. What is the best way to select a page in a multi-language environment? Explanation: The site I'm working on has 2 languages - EN, DE I have a page with EN name "sample-page" and DE name "beispiel-seite". How can I select this page language-independent via $page variable? Thanks for your help! Martin
  17. @Zeka thanks for the hint, I’ll try this. But the code from my post comes from _main.php template preinstalled with PW and I thought it should work. Hmm...
  18. Hello there, I'm very new to Processwire CMS and here is my first question: I've added a custom field to the language system template called languagecode (holds the ISO language code for each language). How can I access this custom field? I tried this for the $languages array: foreach ($languages as $language) { ... $hreflang = $page->getLanguageValue($language, 'languagecode'); ... } but return values are empty. BTW, this works as expected: <html lang="<?php echo $user->language->languagecode; ?>"> Thanks in advance for your help! Martin
×
×
  • Create New...