Jump to content

abdus

Members
  • Posts

    743
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by abdus

  1. The $value is to use any value as if it was $page->$fieldName value, it's not $data as in render() method public function renderField(Page $page, $fieldName, $file = '', $value = null) { // .. if(is_null($value) && $fieldName) $value = $page->getFormatted($fieldName); if(is_null($value)) return ''; // ... $tpl = $this->wire(new TemplateFile($renderFile)); $tpl->set('page', $page); $tpl->set('value', $value); $tpl->set('field', $field); return $tpl->render(); }
  2. I can also vouch for Mailgun. Its great, never had problem for the last 3 years I've been using it. Free tier is very generous too.
  3. Try using an absolute URL for the redirect. $pages($contactPageID)->httpUrl . '#form-top'; This one works for me // test-template.php $session->redirect($pages(1)->httpUrl . '#target'); $session->redirect($pages(1)->url . '#target'); // this one works as well // home.php <div class="" style="min-height: 110vh;"></div> <div id="target">heyylo</div>
  4. It doesn't work because renderField() method doesn't support additional data to be passed. You can render the file manually using $files->render() and by populating $data argument. Also remember to populate 'value', 'field' and 'page' if you're utilizing one of them in the field template. public function ___renderField($fieldName, $file = '', $value = null) {...}
  5. That's one of the things I've always hated with Wordpress. Absolute links everywhere.
  6. <body pw-prepend='html-body' class='bgimage'></body> Both id and pw-prepend/append attibutes be present for it to work <div id='main' class='bar' pw-prepend><p>
  7. From the core: * Modifying attributes on an existing element * * <div id='main' class='bar' pw-prepend><p>This prepends #main and adds "bar" class to main</p></div> * <div id='main' class='foo' pw-append><p>This appends #main and adds a "foo" class to #main</p></div> * <div id='main' title='hello' pw-append>Appends #main with this text + adds title attribute to #main</div> * <div id='main' class='-baz' pw-append>Appends #main with this text + removes class “baz” from #main</div> * -class feature looks interesting too
  8. Hmm so we can use both id and pw- attributes? Interesting..
  9. I'm sure you'll enjoy it. For more complex markups that require lots of logic, I use wireRenderFile but return value instead of echoing, so it acts like a function with in its own file. Another thing I've recently started doing is that removing all templating logic out of template files and using it as controllers instead. For different views I create a file under templates/views/<templatename>.php and it gets appended after the template file automatically (with the hook below). This means inside the template file there's only the logic left. wire()->addHookBefore('PageRender::renderPage', function (HookEvent $e) { /** @var Page $page */ /** @var HookEvent $event */ /** @var Template $template */ $event = $e->arguments(0); $options = $event->arguments(0); $page = $event->object; $template = $page->template; // do not overwrite previous appends prepends $options['prependFiles'] = array_merge($options['prependFiles'], [ "{$template}.routes.php", "_common.php", ]); $options['appendFiles'] = array_merge($options['appendFiles'], [ "views/{$template}.php", "_after.php", "_main.php", ]); $event->setArgument(0, $options); });
  10. Yeah, it's how I've been doing it until I met markup regions, and still have to do it so on some occasions. But building segments in HTML and seeing it magically get injected into your layout without touching anything is indisposable. As you're not working inside strings, syntax highlight and intellisense of IDEs are available too. Now having tasted the convenience, I dont want to go back to having template logic in my HTML (except ifs and loops). Markup regions feature is like a template engine but in a pure php. I refrain from tainting it, so to speak.
  11. Unfortunately append / prepend operations do not modify region attributes. Only replace does. I'd love to have that feature too
  12. Go to Modules > Configure > ProcessPageEditLink, you'll see the option to use absolute links. But, it is the default option. Hmm, weird.
  13. This one seems to work for me. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'page_list') { $event->return = $event->object->hasPage->children; } }); Edit: Nope. ->hasPage gives the repeater item page (not exactly, keep reading), ->arguments('page') gives the page being edited. $this->addHookAfter('InputfieldPage::getSelectablePages', function (HookEvent $e) { if ($e->object->hasField->name != 'testReference') return; $e->return = $e->arguments('page')->children; }); Weird thing is that InputfieldPage::getSelectablePages is called twice for every new repeater item. On the first call, hasPage and arguments('page') are identical, but on the second call, hasPage is the repeater item, arguments('page') is the page being edited. So using the argument seems to be the better option.
  14. Try using ... ('page')->getForPage()->children instead
  15. Is this file called by PW? If not, wire() will not be defined and you'll need to bootstrap PW into your script. https://processwire.com/api/include/
  16. Call it like \ProcessWire\wire()->config Or add <?php namespace ProcessWire; at the top of your file.
  17. https://security.stackexchange.com/questions/127808/is-array-injection-a-vulnerability-and-what-is-the-proper-term-for-it
  18. I created an issue https://github.com/processwire/processwire-issues/issues/388
  19. Hmm. One thing I missed is that ProcessPageEdit allows super users to pick any template // ProcessPageEdit.module protected function getAllowedTemplates() { // ... foreach($allTemplates as $template) { // ... if($isSuperuser) { $templates[$template->id] = $template; } else if($template->noParents == -1) { // only one of these is allowed to exist if($template->getNumPages() > 0) continue; } else if($template->noParents) { // user can't change to a template that has been specified as no more instances allowed // except for superuser... we'll let them do it continue; // ... } // ... return $templates; } I dont think picking repeater templates should be allowed. if block shouldn't start with checking superuser, but it should come after. This order should stop repeater templates from showing. if($template->noParents == -1) { // only one of these is allowed to exist if($template->getNumPages() > 0) continue; } else if($template->noParents) { // user can't change to a template that has been specified as no more instances allowed // except for superuser... we'll let them do it continue; } elseif($isSuperuser) { $templates[$template->id] = $template; } Can someone confirm changing the order (ProcessPageEdit.module, at line 1973) fixes the issue?
  20. Repeater templates are set to have no parents // FieldtypeRepeater.module /** * Populate the settings for a newly created repeater template * @param Template $template */ protected function populateRepeaterTemplateSettings(Template $template) { $template->flags = Template::flagSystem; $template->noChildren = 1; $template->noParents = 1; // prevents users from creating pages with this template, but not us $template->noGlobal = 1; } which should be enough to keep them off of ProcessPageEdit (page edit screen, template option at settings tab) /** * Returns an array of templates that are allowed to be used here * @return array|Template[] Array of Template objects */ protected function getAllowedTemplates() { // ... foreach($allTemplates as $template) { // ... } else if($template->noParents) { // user can't change to a template that has been specified as no more instances allowed // except for superuser... we'll let them do it continue; } // ... } return $templates; } and ProcessPageAdd (new page screen) protected function ___getAllowedTemplates($parent = null) { // ... foreach($allTemplates as $t) { // ... } else if($t->noParents) { continue; } // ... $templates[$t->id] = $t; } // ... return $templates; } But seeing how they still show up, I'm guessing somehow $noParents is corrupted to a falsy value. Checking the DB, you shouldn't have noParents entry in templates table for repeater templates. Otherwise I'm not sure how it's possible at all.
  21. Yeah :(, it cant perform migration over SSH.
  22. Hmm, turns out MySQL offers a similar tool for migration https://dev.mysql.com/downloads/workbench/
  23. If you're using PHPStorm, there's a sync feature that lets you diff between remote & local and sync differences automatically (other Jetbrains IDEs should have it too) https://confluence.jetbrains.com/display/PhpStorm/Sync+changes+and+automatic+upload+to+a+deployment+server+in+PhpStorm
  24. Some modules to get you started http://modules.processwire.com/modules/auto-export-templates-and-fields/ http://modules.processwire.com/modules/module-settings-import-export/ https://processwire.com/blog/posts/processwire-3.0.71-adds-new-core-module/ Edit: As for my setup, I use PHPStorm (free for students, yay!), and a Ubuntu VM. Webpack for JS + PHPStorm's own file watchers for scss. I back up themes and modules I develop using git to GitLab private repos. For syncing local & production server, you can set up a SSHFS and bootstrap remote PW into yours and export local changes to remote. I haven't tried this, and not sure if it'll work, but I'll give it a try and update you if it's worth trying, and probably write a tutorial on it.
  25. I dont think it works like that. Being a repeater, FieldtypeFieldsetPage saves its content into pages under /admin/repeaters, and you cannot move them around like basic data types, as matching data is done using page names of the repeater items and its parent. You'll have to clone/move the repeater items to a new location and change their names accordingly. I haven't used the action from @adrian's module as per @bernhard 's recommendation, but it sounds promising.
×
×
  • Create New...