Jump to content

applab

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by applab

  1. Thank you very much, that has got me up & running :-) Thanks to your tip I've also realised that I can check 'Modules Loaded' in my Tracy debug bar if I encounter a similar situation again. Cheers, Martin.
  2. Hi, I've installed the module FieldtypeComments and now I want to add comments via the API as shown here https://processwire.com/talk/topic/357-creating-comments-via-api/ But I'm getting a 'class not found' error on this line $c = new Comment(); I have no problem creating pages with `new Page();` but I'm unable to create a comment with `new Comment()` Can anyone point me in the right direction? Thanks, Martin.
  3. Hi @bernhard, sorry for the delayed response but I'm flitting between 2 projects and have just come back to this. From looking at that Tracy source code and reading the Tracy docs it looks like the method used relies on the alt-template being in the main /site/templates/ folder and having a recognisable suffix. My goal is: 1) to keep dev templates outside of the main templates folder (eg. have /site/templates/ and /site/dev-templates/) 2) for /site/dev-templates/ not to require a full set of templates, just one or two that are being worked on, and to 'fallback' to the main templates folder if there is no tpl for the current request in dev-templates. My problem is that include files and assets are no longer in the same relative location if the alt-template is used when the dev-tpl is not in the same folder as the main tpl. TBH, it's not super-high priority but I think it would be useful both when collaborating or when modifying a live site so I will come back to it at some point.
  4. Hi @monollonom Doing it this way still encounters the problem I had with my original method, ie. it finds the alternate template but require/include files aren't found as relative paths are now different. I'm not sure how I'm going to approach that, I will give it some thought over the weekend. BTW, because I have an extra level of folders I had to modify your code slightly to append a / after the username. $userTpl = str_replace("templates/", "templates-dev/" . $event->user->name . '/', $tpl->filename); Thanks for giving it some thought :-)
  5. Thanks @monollonom, though as per @androbey's suggestion the conditional is not necessary if the username matches the folder name and can be used directly to construct a path. On a side note, I wasn't aware that fieldTemplates was a thing until I saw your post so I've learned something very useful :-)
  6. This is exactly how I usually approach it. In this case though I was hoping to achieve a setup where each dev's folder does not need to contain a full set of template files, just the one or two they are working on, and for any template not found in the dev's folder it will fallback to the main template directory, ie. the same way Wordpress child themes work.
  7. Thanks @androbey, I hadn't seen that post but I have used render() plenty of times, I might end up going that way. I've sort of got it working but I had to put my dev templates in the main template folder (with a different name) otherwise all my include paths are wrong. I was hoping to keep them separate.
  8. Hi, I'm trying to change a template file at runtime based on the logged in users name. in addition to the /site/templates/ folder I have a /site/templates-dev/ folder, and under that is a folder for each developer. so, if I'm logged in as `timmy` and a file exists at `/site/templates-dev/timmy/article.php` then that file should be used, otherwise use `/site/templates/article.php`. in /site/ready.php I have $fp = $config->path('site') . 'templates-dev/' . $user->name . '/' . $page->template . '.php'; if(file_exists($fp)) { //echo "found tpl!"; $page->template->filename($fp); } If I uncomment the `echo` statement then I can see that it's finding the alternate template but if I view the page it's just blank (status 200, 'this request has no response data available'). Is anyone able to point me in the right direction please? Thanks, Martin.
  9. Thanks @kongondo, that is precisely the info I needed. Next time I'll RTFM a bit more before I post!
  10. Hi @Zeka, Yes, I am using $modules->get("MyModule") in my front-end template. I was just surprised to see MyModule get installed as a result of that code rather than throwing an error, which is what I was expecting. I've achieved my original goal of preventing the install in that situation but I've realised that I still need to use isInstalled() in my front-end templates to avoid runtime errors so, thanks.
  11. Hi All, I'm making my first serious foray into module development and I've discovered some behaviour which I found surprising... If I uninstall my module from the backend but do not delete the file, then I refresh a front-end page that is using that module, I would expect to see some kind of error but what happens is the module gets automatically re-installed. I can mitigate this behaviour by wrapping my front-end code in: if(modules()->isInstalled('MyModule')) { ... } but that doesn't seem like the best approach if the module is used in multiple places. Is there something I can add to my modules install() method to prevent it getting auto-installed in this situation? Thanks.
  12. Has anyone implemented Flarum yet? I like the look of it but I'm concerned that it seems to be in perpetual beta. My top contender at the moment is Vanilla but it's use of Smarty is putting me off.
  13. My method is this... The user will register using their email address and never actually know the username that's used to log them in behind the scenes. On registration the username will be derived from the email address and if there's a clash I'll simply add an incremental numeric suffix. When the user comes to login, the username is looked up from the email address (which is, of course, unique) and it doesn't matter if a suffix has been added or not, as long as it's the right username for the email address.
  14. I had a feeling that the failure of $session->login($email, $pswd); might be related to email sanitization, but since my solution worked I gave up pondering. Before trying it I didn't expect it to work as I thought that without a logged-in admin session I wouldn't have permission to query admin pages. But your solution of using a sanitized email as the username and then sanitizing $input->post->email before calling $session->login() also makes a lot of sense. I'll be doing the registration form next so I might adopt that approach.
  15. Ok, I've found a workaround by using the email to lookup the user name and then logging in with that instead. $e = $input->post->email; $p = $input->post->pswd; $u = $pages->get("email={$e}")->name; $session->login($u, $p);
  16. I have configured ProcessLogin to use email instead of username (and enforced unique values for the email field). I can login to my admin just fine using an email address but I'm trying to create a front-end login form and it's failing. I've copied the example from https://processwire.com/api/ref/session/login/ and replaced the two params with hard-coded values known to work for backend login but I just get 'Sorry Bob'. Anyone have pointers on how to get this working from the front end?
  17. Doh!, you are indeed correct. How did I miss that in the 2 line readme! Thanks.
  18. The last time I used this module was on Dev 3.0.149 and it worked fine (in conjunction with your AdminCustomPages module). I've just installed on Dev 3.0.155 and it seems to be having no effect. Any ideas?
  19. Hi Sierra, It looks like you haven't disabled the 'automatic prepend/append' option for your template. Navigate to Setup->Templates->YourTemplate Go to the 'Files' tab and tick the two 'Disable automatic...' boxes. Does that fix it?
  20. I'm still at the shallow end of the learning curve with Docker so I can't answer from experience but, AIUI... Yes, build a Docker image locally for your app/site and it should run seamlessly on any Docker-supporting host, which includes things like AWS. Regarding performance, according to this IBM research paper "The general result is that Docker is nearly identical to Native performance and faster than KVM in every category" http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf Just found this, it looks like others have made more progress
  21. I'm a Linux guy end-to-end, but if I had to develop on a Windows machine my go-to solution would be to use https://www.virtualbox.org/ to setup a local Linux dev environment. I've also had a tinker with https://www.docker.com/ which looks like "the right way to go" but I don't it well enough yet.
  22. thanks Teppo, worked great after 1 amendment: on first attempt I got an error: "Error: Exception: Can't save field from page 1028: /blog/posts/test-post/: Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved." so, I did as the error suggested end ended up with: $comment = new Comment; $comment->text = "my text"; $comment->cite = "my name"; // etc. $p = $pages->get('/about/'); $p->setOutputFormatting(false); // added $p->comments->add($comment); $p->save('comments'); checking the PW cheatsheet for $page->setOutputFormatting() makes it clear why that's needed.
  23. I have a template which includes a "comments" field using the core Comments field type (FieldtypeComments) Is there a way to post a comment to a page which uses this field, programmatically, from a different page?, ie. not the current $page. something along the lines of: $my_comment = array( 'cite' => $comment_cite, 'text' => $comment_text, 'created' => $comment_date ); $p = $pages->get('my-selector'); $p->comments->add($my_comment); // no such method! tia.
  24. Hi All, I've just noticed that the latest stable version has moved on to 2.4, when did that happen?, did I miss an announcement?? I'm too busy to download and take a look right now, is there a changelog anywhere that will inform us what to expect in the new version?, or maybe a forum post that I should check out? cheers, Martin.
×
×
  • Create New...