Jump to content

elabx

Members
  • Posts

    1,303
  • Joined

  • Last visited

  • Days Won

    16

Everything posted by elabx

  1. Try: $datetofind=strtotime($date); foreach($page->special_days->find("date_value={$datetofind}, time_from!='', time_to!=''") as $special_day) { $slot_txt.=$special_day->time_from." to ".$special_day->time_to."<br/>"; }
  2. i also stumbled on this issue! Needed a drink too! Even asked a few days ago why this behaves like this! https://processwire.com/talk/topic/14638-no-input-data-when-post-form-with-ajax/?tab=comments#comment-163444
  3. Can confirm it works on PW3 too, I had some issues with the included AWS SDK: So just for trying something out because I couldn't figure out anything from the error, I switched to installing the Amazon SDK through composer to get the latest version of the SDK and I basically just had to change how the S3 client is initialized. $this->client = new S3Client([ 'version' => 'latest', //Hardcoded value, think this has to do with the SDK version? 'region' => 'us-east-2', //Hard coded value for now, could be a config field 'credentials' => [ 'key' => $this->s3_key, 'secret' => $this->s3_secret, ], ]); Also removed the require_once for the included SDK.
  4. Doesn't the previous output the link already for download?? You can use an if statement to check if there is an uploaded file: <?php if($publication->repeater_download):?> <p><?=$publication->repeater_description?></p> <a href="<?=$publication->repeater_download->url?>">Download</a> <?php endif ?> It uses naming convention, the following code will render the file content in site/template/fields/Repeater_publication.php : (EDIT: Edited some code on previous post, I was mixing Repeater Matrix field rendering with normal Repeaters) <?php //Render the repeater field in the current page $page->render("Repeater_publication"); And inside site/template/fields/Repeater_publication.php : <?php foreach($value as $publication):?> <p> <?=$publication->publication_year?></p> <?php endforeach?> Maybe you can save this for later if you already got the rendering almost done with a more common approach
  5. Try setting the output formatting for the $flexibleContentRepeater repeater matrix item (which is a page!) $flexibleContentRepeater->of(false); I also think you shouldn't be saving the page inside the hook:
  6. I think you might have a mistake here: $publications = $subpage->publication_year(); If I understand your setup correctly that returns a year integer, so looping on that will have no relevant effect. I think the final code could look like this: <?php foreach($page->children() as $subpage): ?> <!-- $subpage are the "year" pages --> <h1>Publications on: <?php $subpage->title </h2> <!-- eg. Publications on 1997 --> <?php foreach($subpage->Repeater_publications as $publication): ?> <p><?=$publication->repeater_description?></p> <a href="<?=$publication->repeater_download->url?>">Download</a> <?php endforeach; ?> <?php endforeach; There is a way to render the repeater field as its own template (or any field for what matters) with a feature called field rendering, you would have to create a template file as: templates/fields/Repeater_publication.php that actually renders some markup when calling the render method on the repeater field reference. <?php foreach($page->children() as $subpage): ?> <!-- $subpage are the "year" pages --> <h1>Publications on: <?php $subpage->title </h2> <!-- eg. Publications on 1997 --> <?php echo $page->render("Repeater_publications"); ?> <?php endforeach; And inside site/template/fields/Repeater_publication.php : <?php foreach($value as $publication):?> <p> <?=$publication->publication_year?></p> <?php endforeach?> Check this blog post for more info on field rendering, to see which variables are available in the template file: https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/#processwire-3.0.5-introduces-field-rendering-with-template-files
  7. Haven't tested but from what I read from the core files, is that InputfieldAutocomplete uses ProcessPageSearch to look for the pages matching the fields options. You could hook into the executeFor() method on ProcessPageSearch and replace the returned output with another list rendering of your own mix of pages, the ones found by the module, and the ones you define as curated at the beginning of the rendered list. I'd even bet you could add some CSS classes to make them look different.
  8. Check this documentation page, you can also add properties: https://processwire.com/api/hooks/#add_new_method
  9. Could you double check the selector is ok?? I threw in some invented field names in the selector. (sorry to omit that) It seems to me that the $submitted is not throwing a truthsy value (maybe try $submitted->count() so it returns a number which evals to true except for 0 pages found) and it's trying to create a page with the same page name. (John Smith, will crate page john-smith), also for setting the page rather use the $sanitizer->pageName(). Also, reviewing the code, maybe it's more correct to do this: if(isset( $_POST['submit'])){ //Rather only get the first page $submitted = $pages->get("parent=/entries/, (submitter_name={$input->post->name}),(mail={$input->post->mail})"); //Checks for page id, if not it's NullPage object if($submitted->id){ //Code from before }else { $session->redirect("?alert=existing-submission"); } }else { $session->redirect("?alert=form-failure"); } Hope i didn't make this more confusing haha
  10. Here the url should be add-new-recordal, so it gets read by the process module: $wire->addHookAfter("ProcessPageLister::execute", function($event) { if(wire('page')->id === 1413) { // the particular Lister instance page id $out = $event->return; $out .= ''; $btn = wire('modules')->get("InputfieldButton"); $btn->attr('data-href', "./add-new-recordal/"); $btn->addClass("pw-modal"); if(!$this->config->ajax) $out .= $btn->render(); $event->return = $out; } } I have done this in init.php but my wild guess is it should work on ready.php too: $wire->addHook("ProcessPageLister::executeAddNewRecordal", function($event) { // // Create new page and redirect to its edit section $p = new Page(); $p->template = '02_template'; $p->parent_id = 1040; $p->name = 'recordal_' . $pageRecordalsMicrotime; $p->title = 'Recordal_' . $pageRecordalsMicrotime; $p->created_users_id = $this->user->id; $p->of(false); $p->save(); $this->session->redirect(wire('config')->urls->admin."page/edit/?id={$p->id}&modal=1"); } From what I can see, the creation of the page and redirect is already performed in an iframe modal, so it will all happen in the iframe opened with the button you are rendering. Or maybe I'm missing a point here
  11. if(isset( $_POST['submit'])){ $submitted = $pages->find("parent=/entries/, (submitter_name={$input->post->name}),(mail={$input->post->mail})"); if($submitted){ $u = new Page(); $u->template = "entries"; $u->parent = $pages->get("/entries/"); $u->name = $sanitizer->text($post_name); $u->title = $sanitizer->text($upper_name); $u->save(); $u->setOutputFormatting(false); $session->redirect("?alert=form-success"); }else { $session->redirect("?alert=existing-submission"); } }else { $session->redirect("?alert=form-failure"); } This check is first_name OR mail exists already (and checks for exact value! maybe for name you want: name%=$input->post->name).
  12. What about serving the data in an endpoint? Like, not actually write it to a file but have a json response in an endpoint and asynchronously request for that and have your scripts just respond to that.
  13. Maybe it's a permission issue in the repeater matrix template used by the repeater matrix field?? Though makes me wonder why it works on Text type because that one uses the same template as the other types.
  14. You can check for AJAX calls with: $config->ajax Sets to true if request is async.
  15. Yes!! It all worked perfectly, thanks!! Thought it was taken for granted lol sorry, this is the working code: $wire->addHookBefore("TemplateFile::render", function($event){ $templateFile = $event->object; if($templateFile->page->template == "repeater_content"){ $customFileName = $this->config->paths->templates . "fields/content/{$templateFile->page->type}.custom.php"; if(is_readable($customFileName)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } } elseif($templateFile->page->template == "home" || $templateFile->page->template == "basic-content" ){ $customFileName = $this->config->paths->templates . "{$templateFile->page->template}.custom.php"; if(is_readable($customFileName)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } } }); I have some hardcoded if statements because I don't want to be checking for EVERY template, but this works nice for repeater matrix (which uses TemplateFile to render the matrix types) and any other template. Also my first snippet was misleading because I didn't want to do a user check, so I removed that too.
  16. Maybe that page also has a contact-form template assigned? If you do a $pages->get() it will only return the first page matching your selector , so if you have multiple pages with template "contact-form", it might not return the one you think of, but the first one PW encounters.
  17. Why don't you have a text field in the category page you just created? After created, you can click the title (if using ASM Select for example) to open the page and add more content.
  18. One issue is I am not using delayed output but rendering normally through each template/file. Another issue is that I am using also repeater matrix heavily and to keep things organized I also decided to declare the field rendering in each "matrix type" file, so I also wanted to had "alt templates" for this repeater matrix fields rendering.
  19. Was just driving back when I thought: Why the heck am I just not checking if the file exists, though I didn't know about is_readable Thanks @kongondo, @Robin S !
  20. Hi, I've gone a different way to achieve kind of "auto swap" of template files through hooking TemplateFile, because I wanted to swap template files if a template file with some naming convention exists (eg. home.custom.php replaces home.php) I'd like to ask for some opinions about the performance of this hook and if it makes a sensible approach because it feels a way too much to check for files on disk on every template render: $wire->addHookBefore("TemplateFile::render", function($event){ if($this->user->name == "admin"){ $templateFile = $event->object; if($templateFile->page->template == "repeater_content"){ $existingFiles = $this->files->find($this->config->paths->templates . "fields/content/"); $customFileName = $this->config->paths->templates . "fields/content/{$templateFile->page->type}.custom.php"; if(in_array($customFileName, $existingFiles)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } elseif($templateFile->page->template == "home" || $templateFile->page->template == "basic-content" ){ $existingFiles = $this->files->find($this->config->paths->templates); $customFileName = $this->config->paths->templates . "{$templateFile->page->template}.custom.php"; if(in_array($customFileName, $existingFiles)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } } } });
  21. Why is this mandatory? Does it have to do with template configuration of trailing slashes?? Can this be altered to don't matter in a global way??
  22. This works?? strtolower($page->options_field->title);
  23. Doing this myself right now in a project, and very weird what's happening to you because I'm also using the table field inside a RepeatrMatrix and I'm not having any issues with adding rows.
  24. Don't think this is possible because Table field uses it's own schema and adds a database column per table column, so changing it in the field would change it to all fields it is instantiated. The quickest idea I have to hack around this is to use RuntimeMarkup field and render your custom inputfield using jQuery datatables or something simliar and save it's data in a hidden text field).
×
×
  • Create New...