-
Posts
1,065 -
Joined
-
Last visited
-
Days Won
11
Everything posted by Zeka
-
@adrian Do you have a future request on git, so I can support it? As for Console panel, both of your snippets didn't work. I have sent you a PM.
-
Are you sure that you allowed alternative language for these pages? ( Checkboxes on the settings tab).
-
[SOLVED] Multi-instance Support in Multi-site Setup
Zeka replied to kongondo's topic in API & Templates
@kongondo I do. I would be able to test it tomorrow if still needed. -
@adrian Quite a noob question about WireExceptions. Have two exceptions ( output of PW logs) : exceptions 2018‑03‑02 15:34:22 | admin | http://test.local:4000/shop/Method | TemplaterLayout::render does not exist or is not callable in this context (in D:\laragon\www\test\app\wire\core\Wire.php line 519) modules | 2018‑03‑02 15:31:10 | admin |http://test.local:4000/shop/ | Failed to ready module: Templater - Method TemplaterLayout::setTemplateFile does not exist or is not callable in this context The first one generates full report like The second one is only visible in PW logs panel without full report. Why are they handled in different ways? Thanks.
-
@adrian Here is the full code of the hook, not sure that it will be helpful to debug the issue. Currently, have to finish module and will upload it tomorrow. public function hookAfterTemplateRender($event) { if ($this->wire('page') === null || $this->wire('page')->template->name == 'admin') { return; } $template = $event->object; $options = $template->options; if(is_array($options) && array_key_exists('pageStack', $options)) { $view = $this->wire($this->api_view_var); $layout = $this->wire($this->api_layout_var); $page = $this->wire('page'); if($template->halt) { return; }; if (is_file($this->getViewFile($page->template->name))) { $view->setFilename($this->getViewFile($page->template->name)); } else { throw new WireException("View file for this page template does not exist"); } $view_output = $view->render(); if (isset($layout->template) && $layout->template !== 'none') { $layout->setFilename($this->getViewFile($this->layouts_dir . '/' . $layout->template)); $layout->set($this->api_view_var, $view_output); $event->return = $layout->render(); } elseif(isset($layout->template) && $layout->template === 'none') { $event->return = $view_output; } } }
-
amp Routing users to url segments once on the site
Zeka replied to louisstephens's topic in API & Templates
Maybe you can hook Page::path and check if there is urlSegment and then append /amp/. wire()->addHookAfter("Page(template=news)::path", function($e) { $input = wire('input'); if($input->urlSegment1) { $e->return = $e->return . "amp/"; } }); In that way, if a user visits AMP version of a page all links will be linked to AMP versions of other pages. -
Importing different arrays (pageArray/regular PHP array) together
Zeka replied to a-ok's topic in General Support
You can use explode method to get only need properties of pages, so you can equalize array structure of pages and items from the Instagram feed. $x = pages('template=product')->explode(['id', 'created', 'title']); $y = getInstagramFeedArray(); $result = array_merge($x, $y); -
Hi @adrian I have a hook to 'TemplateFile::render' which replaces template output. In the hook, I check whether it's the main template of the page like if ($this->wire('page') === null || $this->wire('page')->template->name == 'admin') { return; } $template = $event->object; $options = $template->options; if(is_array($options) && array_key_exists('pageStack', $options)) { ........... } } But when I run any code inside Console panel I get the output of entire page render. Is there a way how I can prevent this behavior?
-
@Robin S Thank you once again for your explanations and all help. You were right, the issue was that all dynamically added options were not inside valid options of Input field. Got it working by putting all possible options before input processing. $wire->addHookBefore('InputfieldSelect::processInput', function($event) { $field = $event->object; if ($field->name === 'product_uses') { $items = $this->pages->find('template=repeater_product_uses_list')->explode('title', ['key' => 'id']); $field->addOptions($items); } });
-
@Robin S While trying to debug "isValidPage", I tracked down that second Page reference field is not recognized as changed and looks like it's not processed. I get a notification that only first "parent" field was changed. Also, there are calls of 'InputfieldPage::isValidPage' only for "parent" field. Before/after hook to Pages::saveReady also tells that field is not changed. Any thoughts where should I look? I'm very appreciative of your help.
-
@Robin S I faced an issue: When I change first Page reference field I get new dynamically added options in the second field and if I choose these newly added options and save a page they disappear and not saved in a field. Is there some validation mechanism that I missed?
-
Hi! I have a page with a repeater field with a nested repeater field. On another page, I have page reference field (Asm) where items from nested repeater could be selected. In settings for this field I set "Custom format" for field label and "{title} | ({parent.title}) as a 'page custom label format' then I get 'title | (1518957362-4249-1)' as labels where 1518957362-4249-1 is the actual parent of this repeater item in page tree. Am I right in saying that there is no way to get title or another property of parent item? Also, as I can see, there is 'getPageLabel' method, but it's not hookable. Any thoughts? And one more question, is there getForPage() in dot notation? (e.g page.getforpage.title ) Thanks.
-
Does PW keep values retrieved from the database in memory?
Zeka replied to Robin S's topic in General Support
@Robin S I fas as know they are cached somehow, but I don't remember where I'he read it. Only first usage results in DB query. Actually, you can check this behavior by looking at PDO queries count in PW debug panel. Also would like to get more efficient answers. -
Maybe you can use multi-instance functionality for permanent storing of test data in separate DB? https://processwire.com/blog/posts/multi-instance-pw3/
-
@Robin S Thanks one again. Got it working. The first hook is to 'InputfieldPage::getSelectablePages' so on initial load or when a page is being edited not for the first time I get a desirable result. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'product_shop_types') { $page = $event->arguments('page'); $items = new PageArray(); $categories = $page->product_shop_categories; foreach ($categories as $cat) { $items->import($cat->product_shop_use_list); } $event->return = $items; } }); As dependent selects functionality relies on '=page.' pattern in the selector and I had to somehow identify this calls to ProcessPageSearch I made a hook to 'InputfieldPage::render' where I set id=page.product_shop_categoreis to get id values for further usage and custom_search=product_shop_types to identify the request. $wire->addHookBefore('InputfieldPage::render', function($event) { if($event->object->hasField == 'product_shop_types') { $event->object->findPagesSelect = "id=page.product_shop_categories, custom_search=product_shop_types"; } }); Third hook to ProcessPageSearch::executeFor $wire->addHookAfter('ProcessPageSearch::executeFor', function(HookEvent $event) { $get_vars = $this->input->get; if ($get_vars->custom_search === 'product_shop_types') { $categories = $this->pages->find("id=$get_vars->id"); $items = new PageArray(); foreach ($categories as $cat) { $items->import($cat->product_shop_use_list); } $return = array( 'selector' => strval($categories->getSelectors()), 'total' => $items->getTotal(), 'limit' => $items->getLimit(), 'start' => $items->getStart(), 'matches' => $items->explode(function($item) { return array( 'id' => $item->id, 'title' => $item->title->getLanguageValue($this->wire('user')->language), 'name' => $item->name ); }), ); $event->return = wireEncodeJson($return); } }); For now, there is only one issue that I get one empty item before other results in AsmSelect and I can't find out why.
-
Thanks, @Robin S I saw that it makes such calls, but thought that maybe I was missing something. /admin/page/search/for?template=90&parent.title=2010|2011.name&limit=999&get=title Will try to use hooks.
-
Hi. I have this setup: 1. Template 'shop'. This template has two fields 'title' and repeater 'product_shop_categories_list' 2. Repeater field 'product_shop_categories_list' also has two fields: 'title' and the second is repeater field with name 'product_shop_use_list'. 3. 'product_shop_use_list' field has only title field. 4. Template 'product' with two Page reference fields 'product_shop_categories' and 'product_shop_uses'. 5. Field 'product_shop_categories' is set to use 'repeater_product_shop_categories_list' template as a selector. So I get all repeater items/pages from 'product_shop_categories_list' field. 6. 'product_shop_uses' field is set to use 'Custom find' with selector 'template=repeater_product_shop_use_list, parent.title%=page.product_shop_categories.name Here is screenshot of repeaters part of the page tree which explains why I use this selector. But it doesn't work. On initial load 'product_shop_uses' field is empty and when I change 'product_shop_categories' field I get all page with repeater 'repeater_shop_use_list'. Is dependent selects functionality intended to work with such setup? @Robin S what do you think?
-
Dynamic page field that depends on value of previous field entry?
Zeka replied to darrenc's topic in General Support
@Robin S Do you mean inside a repeater field or if items inside 'parent' Page reference field is repeater items? It seems like it doesn't work in both cases. -
Page Reference: Customer -> Location - Selection in template
Zeka replied to zoeck's topic in General Support
@zoeck It's doable by two Page reference fields. Take a look at this thread -
While creating repeater field I got this exception after pressing of save button SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'repeater_product_shop_animal_groups_list' for key 'name' I'm sure that there wasn't template with this name. After that, there was no details tab on the field editing page, so I pressed save button again and it went right. After creating some content and writing markup for this field I've discovered that for this repeater field assigned template with name 'repeater_product_shop_animal_groups_list1'. Currently, there is one field and two templates 'repeater_product_shop_animal_groups_list' and 'repeater_product_shop_animal_groups_list1' and all created repeater items are using 'repeater_product_shop_animal_groups_list1' template. I've found several similar threads on the forum, but still don't understand what caused this error. What would be the easiest way to change a template for created items and reassign template for this repeater field to desirable one?
-
Thanks for replies. @bernhard Great site, that's the perfect example of what I need. Several notices: I think that the cart page should contain <meta name="robots" content="noindex"> and if there are no items in the cart it would better to show something like "Your cart is empty" without form. IMHO.
-
Is there a way to combine hooks to reduce the code
Zeka replied to Juergen's topic in API & Templates
Hi @Juergen I'm not sure about $wire->addHookBefore("Pages::trash","Pages::delete", function($event) { .... run code }); But you can define function separately wire()->addHookAfter('Class::method', null, 'myHookFunctionName'); -
Hi. I have a client request to implement simple shopping cart without registration and other basic shop features as order history etc., I was thinking to use sessions for it. Have somebody done something similar? What are pros and cons? Pitfalls that should be avoided? Thank in advance!
-
Markup Cache for products cards, some static parts of pages and WireCache for searches. https://processwire.com/api/ref/cache/ Page cache and ProCache are options if you can implement ajax loading for dynamic parts, but definitely more work.
-
@Macrura For example, I have this hook in module public function init() { $this->addHookAfter('TemplateFile::render', $this, 'hookAfterTemplateRender'); } public function hookAfterTemplateRender($event) { if ($this->wire('page')->template->name == 'admin') { return; } // some logic which I don't want in admin pages } You use WireRenderFIle which is the shortcut of TemplateFile class. In that way, my hook executes also for calls of WireRenderFile method in the module and I get mentioned notices as $thiss->wire('page') is null. So the issue is that I can't find the way how to check and prevent the execution of hook for calls of wireRenderFile. Hope it explains what I mean.