Jump to content

froot

Members
  • Posts

    720
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by froot

  1. I know it looks and sounds simple but it doesn't work. As soon as I echo what I ->render(); the entire page breaks. It returns the entire page inside the <content> tag and inside that one's <content> tag it renders the entire page and so on. I'm using markup regions, I guess that's an issue…
  2. I tried with foreach ($items as $item) $out .= $item->render('somelayout.php') as well, to no effect. Correct me if I'm wrong. This the one that uses a simple array. So I turned to MarkupPageArray, which is the name of the module, ->renderPageArray() is its method that works for PageArrays (as the module name claims). None of the above work for me but completely mess up my layout. Just use foreach like you propose is not as simple as it sounds and the workaround that is needed to make the method that is build around normal php arrays work for wire arrays as well defeats the purpose of why I'm even here. I have a working solution with dozens of ifs and elses, just thought I could find a more elegant, scalable and straightforward solution instead.
  3. // somelayout.php echo $page->title; // somewhere else $items = $pages("template=posts, limit=10"); $filename = 'somelayout.php'; // inside /site/template/ $out = ''; $out .= $items->renderPageArray($filename); // module is installed echo $out; // result: nothing whatsoever.
  4. @Jan Romero so it doesn't work with PageArrays or WireArrays? just with regular php arrays? that's unfortunate… your code returns syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')'
  5. hm… maybe I didn't make myself too clear. So let's say I have an PageArray $items that should get a specific markup aka layout. Let's say the markup is something like… <li> <h3><?=$item->title?></h3> <p><strong>price: </strong><span><?=$item->price?></span> <p><strong>category: </strong><span><?=$item->category?></span> <p><?=$item->body?></p> </li> would I loop through the $items? $filename = "somelayout.php"; foreach ($items as $item) : $out .= $item->render($filename); endforeach; echo $out; or just do: $out = $items->render($filename); echo $out; Don't know why I ask this because both doesn't work but maybe this gives you an idea of my thinking.
  6. Yes, our provider actually does seem to block it at least when using Authentication, regardless of whether or not I "allow" sending without. And that's good, I must say I always found it strange that it's possible in theory to send an email from whatever email, given the right insecure email server. Yes, thanks, I found the ->replyto() method and it works like a charm. Just wondering now, I agree noreply@ is a very good practice, but since WireMail needs to be logged in with the sender's email-account, I need to create a noreply@ email-address and mailbox on my email-server? Thanks so far
  7. OK I just realised that an email send via my contact form only go through when $email is the actual SMTP-user's email address $m->from($email, $fullname); So I understand that by enforcing authentication when sending an email, the ->from email needs to be the authentified user's email. Thus the email that I receive can't and won't have the user's email. That's only possible with a connection without authentication? So I need to include the email somewhere else, in the email's body? So "replying" is not possible as such. Is my assessment accurate?
  8. What's wrong with my code? It just won't send emails. It worked before when not using wiremailSMTP but now it stops. This is used in a contact form. It has to be the code because when I run a test in the module, it works fine and the email reaches me. Even the Promailer-Newsletters using WireMail SMTP work fine now. Even when I put some debug code on the template to be send to me via email with every email, that email reaches me. But somehow the email in question, send with contact form does not. BTW if-condition works fine cause redirection works as well. Here's my code: if (isset($_POST['sendform']) && $captcha->verifyResponse() === true) : $givenname = $input->post->text('givenname'); $familyname = $input->post->text('familyname'); $fullname = $givenname.' '.$familyname; $fullname = ucwords($fullname); $email = $input->post->email('emailaddress'); $subject = $input->post->text('subject'); $message = $input->post->text('message'); $m = wireMail(); $m->to('myemail@mydomain.com', 'my Name'); $m->from($email, $fullname); $m->subject($subject); $m->body($message); $m->send(); $session->redirect($pages->get("/kontakt/danke/")->url); endif; I recently installed a SSL certificate on the webserver, but that should be irrelevant, right? Further settings: port: 587 Allow Connection without Authentication: no SMTP User and SMTP Password provided Use Start-TLS: no TLS Crypto method: 1.2 Use SSL: no Allow self signed certificated: no Thanks for help!
  9. I always thought you can exclude the _main.php file when you include index.php or something. On some page I do an AJAX-call and with the response text I replace the innerHTML of some div. I put the code that is requested via AJAX on a php-file that I put in the root folder, otherwise it also includes the "head" part which is included on _main.php so I would have the entire page inside the mentioned div, which is of course not what I want. This works fine. However, I'd like to clean this up a bit and make use of: if($config->ajax) : … ; else : … ; to either only include the header when it's not an ajax request or exclude them when it is. But include index.php doesn't seem to work. I tried to disable including of _main.php on the template settings and then do if ($config->ajax) : $config->prependTemplateFile = 'includes/_head.php'; endif; But that doesn't do anything. What am I not getting?
  10. thanks @Macrura It's a good start, but still not ideal. Like I said, technically pretty much exactly like the image-tags functionality when you check User selects from list of predefined tags + can input their own So it's possible in theory, I just need it to work for an only-text-field.
  11. I need a field that behaves somewhat like the native image tags field. What I mean is you can predefine values in the field settings, and then, when editing a page with that field, you can select those predefined values but also enter custom values. Is that something that exists already or should I go ahead and try to create a custom field type?
  12. thanks but sorry, doesn't work I get: hasStatus does not exist or is not callable in this context no idea why
  13. @Zeka Yes, I am giving this one a go as we speak So maybe that goes in the right direction? https://processwire.com/api/ref/process-page-add/set-predefined-templates/ but then, after reading an API doc like this I don't feel smarter, maybe even less smart than before. How should I read this? Also, before I try to figure out how to access the array/WireArray of available templates (if I understand correctly these are the only types of arguments accepted here), how is an array going to help me specify the first one? Here's what I have so far… $this->addHook('ProcessPageAdd::executeTemplate', function($event) { $preselect = $event->object; $temps = $preselect->template; // how to select the optional templates? $preselect->setPredefinedTemplates($temps); // but that's an array, how to tell it to pick the first }); OK now you see how my mind works ? EDIT: OK I guess I can do $preselect->parent->childTemplates(); to get the available templates, right?
  14. I tried that, doesn't work. It's also quite hard-coded this way. The real issue is basically that it always changes and remembers the template of the last page which is likely irrelevant. It'd be better if it were consistent, either select none (this we accomplished) or the first (which happens to be the one I want to be selected cause it's alphabetical).
  15. haha OK, so I'm not alone ? I tried, it does what it promises, it disables them all, so none is pre-selected. Now, how to always pre-select the first one no matter what? it says… protected $settings = array( 'noSuggestTemplates' => '', // Disable suggestions: 1|true=disable all, or space-separated template names ); with that in mind I experimented but true seems is the only one that works
  16. OK how did you find this? I'm asking cause it puzzles me how everyone seems to refer to the Github Processwire repository when they need anything while mortals like me are left with the Processwire API documentation. And then a follow up question, how would I use $config->pageAdd then? This might be self-explanatory to someone but it's not to me at all. Do I create a hook? Do I set something to false in the config file? No idea. I thought it would be something like $this->addHookBefore('ProcessTemplate::execute', function($event) {…}); but no. Thanks for help!
  17. fair enough, yes I'm aware I can and I indeed did restrict the selection of templates a bit but that wouldn't solve my issue. It's still more than just one template that need to be allowed and among those, a specific one should be default, no matter what the previously created page's template is.
  18. I want to change the template that gets selected by default when creating a page. Somehow it just always remembers the template of the last page that was created. Though it seems like a small issue, I realise that a number of clients find this quite confusing and understandibly run into issues.
  19. I have different types of content throughout my site that I want to display on one page. For each type of content I have different markup. I'm trying to create a very generic template so that it is easily expandable, maybe someone can help me with ideas how to approach this. Right now I loop through the items and have one function with dozens of if/elseif/else-conditions. Depending on each item's template it renders different markup. Not very pretty. Another idea would be to create individual functions for each different markup and, depending on the template, call the according function. I was thinking I could given the function the same name as the template and in case I add new content with a new template I would only need to add a function with that template's name. So in order to make this work I would need to store each function in a variable with the template's name and then do something like… $sometemplate = $item->template; $somefunction = $sometemplate; call_user_func($somefunction, $item); right? I wonder if there's a even smarter way, what's ProcessWire's approach to that?
  20. how to get all the subfields of a repeater field generically? I'm not talking about a specific field that I know the name of, that's easy, I'm trying to access them in general in the $fields variable itself. Better yet, how to access them by type?
  21. how can I select all pages of which the template has a specific tag? I tried in so many ways, I just don't want to list all the wrong solutions here, so maybe someone can just tell me the right way?
  22. I agree, this made things easier indeed. I had some success and I think one issue was that the hooks were conflicting somehow, I'll elaborate further in the thread I linked above because that's the specific issue I needed help for, this thread here is rather for a general understanding. Please don't tell me this is how you suggest me to know how each individual hook works ? cause if it is then maybe hooks are not for me… Thanks @teppo
  23. OK so I had some progress, the hooks, I guess were conflicting each other. One hook's intention is to delete the page from the other page's table but it was triggered before the page is saved and also triggered the other page's save-event. See here: so basically… page A is the page that is saved page B is the table of content (sibling) page A -> addHookbefore: trash: remove from page B, save page B -> addHook: check siblings -> finds and adds page A -> page A is saved i.e. trashed but stil in the page B list. Here's the code – if you're still interested ? // update TABLE OF CONTENTS when saving individual page :D // works for editing, hiding/unhiding, publishing/unpublishing and trashing :D // does NOT work for moving pages (to different parent) :D // when moving a page, save the former parent page (table of contents) :D $wire->addHook('Pages::saveReady', function($event) { $item = $event->arguments[0]; if ($item->parent->template != 'magazine') return; if ($item->template != 'tableofcontents') return; $parent = $item->parent; $contents = $item->siblings(true); $rows = $item->tableofcontents_table; foreach ($contents as $content) : updateRows($rows, $content, $event); endforeach; cleanRows($rows, $item, $event); }); // update TABLE OF CONTENTS when saving TABLE OF CONTENTS page :D $wire->addHookAfter('Pages::saved', function($event) { $item = $event->arguments[0]; if ($item->parent->template != 'magazine') return; if ($item->template == 'tableofcontents') return; $parent = $item->parent; $toc = $parent->child("template=tableofcontents"); $rows = $toc->tableofcontents_table; $toc->of(false); updateRows($rows, $item, $event); cleanRows($rows, $item, $event); $toc->save("tableofcontents_table"); $toc->of(true); }); // *update TABLE OF CONTENTS when trashing a page :D $wire->addHookBefore('Pages::trash', function($event) { $page = $event->arguments[0]; $parent = $page->parent; if ($parent->template != 'magazine') return; $toc = $parent->child("template=tableofcontents"); $rows = $toc->tableofcontents_table; $page_id = $page->id; $toc->of(false); $item = $rows->get("content_id=$page_id"); $rows->remove($item); $event->message("row deleted"); $toc->save("tableofcontents_table"); $toc->of(true); }); // this just won't work, thought it would work just as well as trashed but nope //$wire->addHookBefore('Pages::moved', function(HookEvent $event) { // $page = $event->arguments[0]; // $parent = $page->parent; // if ($parent->template != 'magazine') return; // $toc = $parent->child("template=tableofcontents"); // $rows = $toc->tableofcontents_table; // $page_id = $page->id; // $toc->of(false); // $item = $rows->get("content_id=$page_id"); // $rows->remove($item); // $event->message("row deleted"); // $toc->save("tableofcontents_table"); // $toc->of(true); //}); // add/update details to pages that are missing from the TABLE OF CONTENTS :D function updateRows($rows, $item, $event) { $item_id = $item->id; $item_url = $item->url; $item_title = $item->title; $item_number = $item->page_number; if ($rows->has("content_id=$item_id") == false) { $row = $rows->makeBlankItem(); $row->content_id = $item_id; $row->content_url = $item_url; $row->content_title = $item_title; $row->content_page = $item_number; $rows->add($row); $event->message("row created"); } else { $row = $rows->get("content_id=$item_id"); $row->content_url = $item_url; // $row->content_title = $item_title; $row->content_page = $item_number; $event->message("row updated"); } } // remove obsolete pages from the TABLE OF CONTENTS :D function cleanRows($rows, $item, $event) { $contents = $item->siblings(true); foreach ($rows as $row) : $row_id = $row->content_id; if ($row_id == '') continue; if ($contents->has("id=$row_id") == false) { $rows->remove($row); $event->message("row deleted"); } endforeach; }
  24. works perfectly. I still have to wrap my head around the preg_replace_callback and references though. Thanks!
  25. [SOLVED] Apparently, if you change the decimal operator to a comma, don't bother changing the price format in that very field's settings in your ProcessWire installation, which is what I did, cause the regex is [-+]?[0-9]*[.]?[0-9]+ and the field note says "Dezimal mit einem Punkt (.) als Trennzeichen". Rather leave it as is, enter the prices with a dot as decimal separator, head over to your snipcart.com dashboard > store configurations > regional settings, simply change it there and snipcart should do all the rest. Taxes work fine this way and frontend shows a comma in lieu of a dot. Anyways, hope that helps someone else in the future.
×
×
  • Create New...