Jump to content

Soma

Moderators
  • Posts

    6,808
  • Joined

  • Last visited

  • Days Won

    159

Everything posted by Soma

  1. Your welcome, thanks for the quick fix it works now!
  2. I understand and know this, but why do you need to get the translation when it is just already there. It will output in the language the user views the page ($user->language) This works just fine in the language the user view the page. echo $fields->get("body")->label; Edit: ah, hm it does not? Ok it doesn't get translated as with page fields. Since it's meant to be used for backend context there's no language value for fields settings. So you either use a $lang variable like this: $lang = $user->language->isDefault() ? "" : $user->language->id; // Default needs no id echo $fields->get("body")->get("label$lang"); Or a little hook to add method to the $fields template API var. // from template or a autoload module $fields->addHook("getLabel", null, "getLabelLang"); function getLabelLang($event){ $field = $event->arguments(0); $lang = wire("user")->language->isDefault() ? "" : wire("user")->language->id; $event->return = wire("fields")->get($field)->get("label$lang"); } // now we use it and it will recognize user lang echo $fields->getLabel("body");
  3. I have a hard time to understand why one need the field labels (in different languages) in the front-end. After all if the it should render the language the user currently is viewing. We covered this already in another thread and there's the solution above and I don't think there's something like you mention on the plan but maybe I miss something. But it would be easy to build a function or module to help out but there's barely anything needed to get a translated label. $body = $fields->get("body"); $lang = $languages->get("de"); echo $body->get("label$lang"); // german label
  4. If you turn off formatting a single image field is also an WireArray again. $page->of(false) $page->image->removeAll(); $page->save();
  5. Since Pagefile is a single file field you would use delete(). You're not dealing with a WireArray then but with the page file itself. Or a $page->file = ""; $page->save(); would also do it maybe. Just wanted to add that if you (or need to) first $page->of(false) (setOutputFormatting), even a single file field will be an WireArray, so deleteAll() should then also work.
  6. I found a nasty bug when moving pages in the page tree in the admin. I have a setup where I have created a new category page and moved all the product pages on the same level into the newly created category. But then the find() I used to get all products from a parent above the category page fails. The product pages have children, which seems to be the key to reproduce this. I also have multilanguage installed but I don't think that does anything. I tried and was abel to reproduce this in my local test install with complete unreleated templates or fields. This is the on second level ... /shop/ /category1/ /newparentpage/ /product1/ (product template) /product-var1/ /product2/ (product template) /product-var1/ When I move "product1" and "product2" inside the "newparentpage" /shop/ /category1/ /newparentpage/ /product1/ /product2/ I can't use following to get all products under "category1" $pages->find("has_parent=category1, template=product"); // returns nothing $pages->get("/shop/category1/")->find("template=product"); // returns nothing $pages->find("has_parent=category1_ID, template=product, include=all"); // returns nothing This got me, as I never experiences something like this. The page tree works and also finding the product with $pages->find("template=product"); // will find all still Also this doesn't happen if the moved product pages have no children. So there's something wrong with the page_parents table I guess, but haven't investigated futher as I'm in a hurry to finish the website. And always then such things happens.
  7. $page->files->deleteAll(); $page->files->delete($pagefile); $page->images->removeAll(); // wirearray $page->save(); http://cheatsheet.processwire.com/?filter=filesdelete
  8. Do you have secure page files enabled in config.php that would be the only thing I can imagine changing files when unpublished.
  9. In a subfunction they aren't available? wire("languages") ? Is available everywhere. this should maybe work. $lang = $languages->get("dutch"); $dutch_field = $page->get("fieldname$lang"); or $lang = $user->language; $user->language = $languages->get("dutch"); if($page->fieldname) { ... } $user->language = $lang;
  10. pages->get(id) will return the page with id. Doesn't matter where it is and what user. It's explicit. As soon as you add another selector, it will behave like a find thus check for if pages can be viewed or accessed. Everything correct here.
  11. Verleser des Tages: "Feuchtgelb".

  12. I also recognized that daytime fields in pw once set and saved then cleaned again it saves the field with the 1970 date. This is like 0 timestamp. It is ok when using in api but when directly queried from db you get the date so you have to take care of those. This is clearly a pitfall and should be fixed. I think I even reported this long time ago on github but not sure anymore.
  13. Yes it does work with PageListSelect and everywhere you see the page tree (naturally).
  14. RT @ryanscherler: I am still constantly surprised how easy things are to build in @processwire #cms

  15. Sorry you didn't get any responses there, but time is limited One way is set user language to the one you want to set the label. Or using the language id to append to "label{LID}" $f = wire("fields")->get("mytextfield"); $lang = wire("languages")->get("de")->id; $f->set("label{$lang}","Mein Textfeld"); $f->save();
  16. Or you could use my ImagesManager module to centralize images. Then use a select to add them to pages. Images are saved as a page. Look in the forum as it's not in the modules repository.
  17. $fs = $template->fields->get("fieldsetfieldname")->children;
  18. Soma

    parentmost

    Look no further http://cheatsheet.processwire.com/?filter=eq
  19. Soma

    parentmost

    If Events all have the same template it would be Which would be the same as $parentmost = $page->parents->eq(2); or $parentmost = $page->parents[1];
  20. ....or simpler version using a "dummy" page array that searches the same pages but not actually sorting, just for the the pager. $limit = 4; $sql = "SELECT id FROM pages INNER JOIN field_mydate ON field_mydate.pages_id = pages.id WHERE status < 2048 AND templates_id = " . $templates->get("basic-page")->id . " ORDER BY DATE(data) DESC, TIME(data) ASC LIMIT " . (($input->pageNum-1)*$limit) . ",$limit"; // run query $res = $db->query($sql); // output events while($row = $res->fetch_array()) { $event = $pages->get($row['id']); echo "<p><a href='$event->url'>$event->mydate | $event->title</a></p>"; }; // generate pager navigation using dummy array $dummies = $pages->find("template=basic-page, mydate>0, limit=$limit"); echo $dummies->renderPager();
  21. Yeah it's not actually simple. An approach would be to create pager manually using the core PageNav class. $limit = 8; $sql = "SELECT id FROM pages INNER JOIN field_mydate ON field_mydate.pages_id = pages.id WHERE status < 2048 AND templates_id = " . $templates->get("basic-page")->id . " ORDER BY DATE(data) DESC, TIME(data) ASC LIMIT " . (($input->pageNum-1)*$limit) . ",$limit"; // run query $res = $db->query($sql); // output events while($row = $res->fetch_array()) { $event = $pages->get($row['id']); echo "<p><a href='$event->url'>$event->mydate | $event->title</a></p>"; }; // generate pager navigation manually include($config->paths->MarkupPagerNav . "PagerNav.php"); $total = $pages->count("template=basic-page, mydate>0"); $pager = new PagerNav($total, $limit, $input->pageNum); $pagerMarkup = ''; foreach($pager as $link) { $class = $link->pageNum == $input->pageNum ? 'on' : ''; // is it the current page? if($link->type == 'separator') $item = '…'; // is it a separator else $item = "<a class='$class' href='{$page->url}page{$link->pageNum}/'>$link->label</a>"; // or a normal link $pagerMarkup .= "<li>$item</li>"; } // output pagernav echo "<ul class='pagernav'>$pagerMarkup</ul>"; Taken from one of my examples: https://gist.github.com/somatonic/5420536
  22. RT @processwire: Field dependencies are coming to ProcessWire 2.4. Here's more about it and a video preview: http://t.co/glRjMsP9BI

  23. I just watched the video at home (damn mobile won't let me). Amazing feature to have! Watching this I think the "required" need to be more visible or red (asteriks). It can be missed too easily. And the show animation need to be much quicker! (lol) Not can we have also a hideIf() and a makeCoffeeIf()... I already see the forum full of posts "It doesn't show when..."
  24. But now you can install modules with the core install already, so first thing you could do is click "new" and enter ModulesManager and download/install, done.
×
×
  • Create New...