Jump to content


  • Posts

  • Joined

  • Last visited

Community Answers

  1. Can's post in recursive page creation was marked as the answer   
    Thank you horst!
    Anyway your code is awesome, so much cleaner! Even though I added a second loop to handle multiple comma (or dash) separated tag groups and added comments your version is still shorter!
    function processTags($tags, $tagParent = 'tags') { $vars = array('sanitizer', 'pages'); foreach ($vars as $var) ${$var} = wire("$var"); // added this loop to split CSV strings // now we can enter multiple seperate tags with children // like "Tag1,Tag2>Child Tag,Tag3" $tagsArray = $sanitizer->array($tags); $return = new PageArray(); foreach ($tagsArray as $tagGroup) { // parts now holds the hirarchical ordered parent list, without the rootParent named in $tagParent $parts = explode('>', $tagGroup); // we need to set the parent for every tag group // which can be a single comment or can have children // otherwise "Tag 3" (above example) would be a child of "Child Tag" $parent = $pages->getByPath("/$tagParent/"); foreach($parts as $part) { // try to get a childpage with name $part and parent = $parent // added second argument (2) to pageName sanitizer for translation // because the page creation uses this, so without it wouldn't find existing pages.. $p = $pages->getByPath($parent->path . $sanitizer->pageName($part, 2)); if(!$p->id) { // if it do not exist, create it now $p = new Page(); $p->parent = $parent; $p->template = 'tag'; $p->title = $part; $p->save(); } // switch parent to the next level: $parent = $p; $return->add($p); } } return $return; }  Thanks a lot horst!!
    EDIT: I changed the $pages->get() queries to $pages->getByPath() which requires PW 3.0.6. Check out Ryans blog post with benchmarks
    EDIT 2: It's now returning the created (or existing) tags.
  2. Can's post in Howto get language code was marked as the answer   
    Hola Hanna,
    actually I dont't know _x() probably this function 
    but __("string to translate") (two underscores) translates strings in template files, or better to say let's you translate via /processwire/setup/languages/
    So in your case you would either change the line from
    <html lang="<?php echo _x('en', 'HTML language code'); ?>"> to
    <html lang="<?php echo _x('de', 'HTML language code'); ?>"> or you in admin you go to /setup/languages/ select your default (german) language and click on_main.php to translate, somehwere there should be written "HTML language code" and there you enter "de"
    I used a different approach
    in _init.php I defined  the following
    // define var $lang for use in tpl files if($user->language->name == 'default') $lang = 'de'; else $lang = $user->language->name; then you can just put this in _main.php
    <html lang="<?= $lang; ?>"> and of course re-use wherever you like.
    Or, you could use the languages title field or add another custom field to language template and name it for example "language_short_code" or maybe you got an already created textfiel which you could re-use here.
    then you don't need to override the default languages name but just output your shortcode field like
    <html lang="<?= $user->language->language_short_code; ?>"> Hope it helps, enjoy Processwire
  3. Can's post in addon domain to specific page was marked as the answer   
    You can use Apeisa's Multisite module
    Thread: https://processwire.com/talk/topic/1025-multisite/
    And in the Docs: https://processwire.com/api/modules/multi-site-support/
    Saludos Can
  4. Can's post in Unable to encode array data for cache.. was marked as the answer   
    Right, haha, that's why I waited with posting this question. Just forgot about additional thought I head...anyway after trying text formatter which didn't made the trick I narrowed it down to a custom character limiting function in my template.
    After trying around I got it working by changing substr() to mb_substr() =)
    Thanks Adam!
  5. Can's post in single-page-shop question - update specific repeater field where another field matches was marked as the answer   
    Got it working myself with this one
    $updated = 0; foreach($order->order_items as $item) { if ($item->order_product == $form_addtocart[item]) { $item->of(false); $item->order_qty += $form_addtocart[qty]; $item->save(); $updated = 1; break; } } if($updated === 0){ $order->of(false); $order_items = $order->order_items->getNew(); $order_items->order_qty = $form_addtocart[qty]; $order_items->order_product = $form_addtocart[item]; $order_items->save(); $order->save(); } Why not editing my post or marking as solved? Hope to get some improvement tips, if there are any (what I guess).
    I´m studious 
  • Create New...