Jump to content

gebeer

Members
  • Posts

    1,554
  • Joined

  • Last visited

  • Days Won

    48

Everything posted by gebeer

  1. Thanks for your reply. $warning will not be available inside the each() callback function because of variable scope. Also the callback function needs to either echo or return something. So I'm afraid your code won't output anything and give a PHP notice like "variable $warning not defined" because you define $warning outside the callback function. This is mentioned in the link that I posted in #1 EDIT Sorry, I overlooked the "use (&$warning)" part. So forget about what I just said I implemented your proposed solution. But still the return value gives me the page ids of pages within the $divesites page array where I would expect it to be empty. EDIT again Got it. I still had $warning = $divesites->each(function... After removing the $warning = part, it works. Only I had to replace {title} with {$item->title} Thanks again. But with my limited PHP knowledge I still don't understand why that is so.
  2. Hello, I'm playing with the new each() API method. $warning = $divesites->each(function($item) { $warning = ""; if (!$item->marker->address) { $warning .= "<div class='alert alert-warning'>coordinates for {title} not set</div>"; } else { $warning .= ""; } return $warning; }); $warning should return an empty string, when all dive site adresses are set. But instead it returns the page id of the last dive site in the loop. When I do it the foreach way $warning = ""; foreach ($divesites as $site) { if (!$site->marker->address) { $warning .= "<div class='alert alert-warning'>coordinates for {$site->title} not set</div>"; } else { $warning .= ""; } } the $warning is an empty string as expected. Why is that? Any pointers would be much appreciated.
  3. I installed an additional language on 2.5.27 dev and everything went fine. Now I added a 3rd language and get several errors: Session: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_title.data1372' in 'field list' Session: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'data1372' Session: SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'data_exact1372' Session: SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'data1372' and warnings Session: language is missing column field_title.data1372 Session: language nl is missing column field_title.data1372 Prior to installing the 3rd language I created an options field. Upon entering the transaltion for the field options I got errors but I didn't note them down. But I cannot save translations for the options. Field for entering translations remains blank after save. Maybe add language error is related to the problems with that options field? I removed the 3rd language and upgraded to 2.5.29 dev. But same errors when adding the 3rd language again.
  4. I you want to convert a PW pages array to json, here is some useful code from Ryan that you can use and adjust to your needs.
  5. You might want to show them the Canton speakers site done with PW that was introduced lately and also announced in PW weekly newsletter. This is a worldwide brand. If they trust in PW, why shouldn't your potential customer. EDIT And cmscritic.com might serve as an example. Their article ProcessWire vs WordPress has some good arguments for PW and against WP. Then there is this article about PW in the german IT magazine c't: "German computer magazine c't has just published an article about ProcessWire, and Tuts+ has announced they are going to commission tutorials on ProcessWire" (taken from PW weekly #43). Some ideas for your points 2 and 3: - you could offer free updates for a period of time since it is so easy to do - if you have the capabilities, you could offer a free port of the system to WP or Drupal in case PW development will stop in the future. This will underline your total confidence in PW And, if you have the opportunity, you could show them the PW backend and how easy it is for editors to work with.
  6. A warm welcome to the forum, tekno (sorry I forgot that in my last post) Did you change the title field to be type "PageTitleLanguage"?
  7. Did you install the Languages Support - Page Names module? You might want to have a read about multi language support in PW And there is a forum section about multi language
  8. Thank you for the quick reply and the fix. I updated and can confirm that it is working now also for multi-language page names
  9. There is a comments fieldtype that makes adding comments to pages a breeze. Since reviews are some kind of 'comments', maybe you can use that module and then extend it to add a rating star system. EDIT here's a thread about adding additional fields to the comments system https://processwire.com/talk/topic/2898-adding-additional-fields-to-comments/
  10. Thank you for this module. I installed it on a 2.5.28 multi language site and it is not changing page names at all, no matter what aettings I try. I the module supposed to work in a multi language environment?
  11. I definitely would encourage you to give PW a try. Most people who took the initial effort are now very happy PW developers You might want to jump right in and have some good reads. Categorizing content tutorial Example code for creating a form with file upload If creating frontend forms through the API is over your head at the moment, you could always use the very affordable paid extension form builder. Easy to use and a big time saver. Multi language And learning PHP when working with PW can be fun. Don't worry, you fill find tons of helpful posts in the forum and the friendly community will help you get started.
  12. In the joomla-vagrant context it makes perfect sense because with that command you can setup a new site in a subdomain so you can have multiple dev sites residing in one virtual machine. But I see your point when considering multi site environments.
  13. Thank you for putting this together. This is absolutely great I came over from Joomla some time ago and one of the many joomla devs have created joomla-console. They combine it with their joomla-vagrant box which is a great tool for development. I am actually still using it for quick setup of PW projects And I've been thinking for quite some time how great it would be to have a console tool for PW. And now it is here. So big thumbs up! I see that there is some kind of naming convention for commands now. Have you ever considered renaming the 'new' to 'site:create' Thats what joomla-console uses and they also have a 'site:delete'.
  14. As a big fan of Pro Fields I use the Textareas Field to combine 2 checkboxes. And I wasn't aware of the options field type. So thanks for the pointers here
  15. I knew that this would cause conflict because there are so many different ways of implementing script loading. So your comments on this are more then welcome. I read and revived this discussion about how to best approach script inclusion when developing a module. And chose a mixed approach because I'm really not sure myself how to best do it and to experiment with different methods. The original approach of the Google Maps module just didn't seem perfect since it forces users to include stuff in the head. So what to do as a user if you don't want to have scripts in <head>. But then I guess there is no perfect way. Main reason for injecting the "inline script" at the very end: wanted to make sure that scripts get loaded in the right order. @Soma why wouldn't you want to have it before </body>? @Wanze thanks for clarifying the terminology. I'm quite new to PW module development. So I really appreciate any input that I can learn from.
  16. Solved this way: I made an additional autoload module 'MarkupAddInlineScript' to execute the hook. In the render() method of the map markup module I assign my inline script string to the page object $this->page->inlineScript = $inlineScript; Now in init() of MarkupAddInlineScript I execute the hook $this->addHookAfter('Page::render', $this, 'addInlineScript'); that calls my hook method public function addInlineScript($event) { $page = $event->object; if ($page->inlineScript) { $event->return = str_replace("</body>", $page->inlineScript . "</body>", $event->return); } } My hook method only executes when $page->inlineScript returns a value other then null. This will happen only on pages that instantiate a map object with $map = $modules->get('MarkupLeafletMap'); As a result I have the script that was previously insertet inline on the page, neatly attached to the end of my page body <script type="text/javascript">...</script> </body> All other scripts that are required for rendering the map are also attached at the end of the body before the "inline script" through $config->scripts->add() in the init() method of the 'MarkupLeafletMap' module. Now when people install this module, they don't have to worry about including the various scripts themselves in the head or body and I can be sure that they get executed in the right order, too. Only thing users of the module need to do now is include <?php foreach($config->scripts as $url) echo "<script src='$url'></script>"; ?> before </body>
  17. Thank you all for the insights on how hooks are working. This really helps me to better understand what is going on. @Wanze How would I approach that? My guess is that it needs to happen during init() of my module, am I right?
  18. I see '<script src="https://maps.gstatic.com/maps-api-v3/api/js/20/9/main.js"></script>' In the body of your html after the map div. Also you have meta tags in your body. This suggests that your template code is somehow messed up and things get loaded in the wrong order. It would help if you could post your postcard.php and head.inc. Sorry, have to go now. Can take a look again tomorrow.
  19. try $map = $modules->get('MarkupGoogleMap'); echo $map->render($page, location);
  20. Great idea Will give this a shot.
  21. I reinstalled the module to make PW know that it is not autoload anymore. Now $this->addHookAfter('Page::render', $this, 'addInlineScript'); is not executed anymore. Doesn't matter whether I call it from init() or render() This confirms for me that modules need to be autoload in order to place hooks in them, like the wiki suggests. I guess I need to find another way of implementing my logic... But thanks again for your help.
  22. Thank ou for the quick reply. Maybe there is some misunderstanding here. I don't want to make a function ___hookable that is part of my module. I want to add an after hook to Page::render where I call my method 'addInlineScript': $page->addHookAfter('render', $this, 'addInlineScript'); This hook call I placed inside the render() method of my module. In the meantime I found out that the hook gets called when I place it in init() method of my module. But I don't want to call it from init() because the 'addInlineScript' method depends on some property that is created in render(). So I need to call the hook from there. The exit() is just there to confirm that my method gets called. I don't want the module to be autoload. I just understood from the wiki that it needs to be autoload in order to call a hook from within it. But I guess I got this wrong. So I made the module none autoload again but it is still being loaded. Has this to do with module cache and how can I make it not autoload again?
  23. Hello, I have a hook in a custom method of a non autoload module and it is not calling my hook method. In the wiki I read Modules that are intended to attach hooks in the application typically should be autoload because they listen in to classes rather than have classes call upon them. If they weren't autoload, then they might never get to attach their hooks. Does this mean that hooks are only working in autoload modules? I added 'singular' => true and 'autoload' => true to getModuleInfo() but still my hook funktion does not get called. My hook call at the end of this render method $this->inlineScript = $inlineScript; $page->addHookAfter('render', $this, 'addInlineScript'); $page object is available. Also tried $this->addHookAfter('Page::render', $this, 'addInlineScript'); and my hook method public function addInlineScript($event) { exit("gbr"); // $value contains the full rendered markup of a $page $value = $event->return; $value = str_replace("</body>", $this->inlineScript . "</body>", $value); // set the modified value back to the return value $event->return = $value; } Why is this not working? Any help would be much appreciated.
  24. I agree. Added all available providers to the select dropdown and have set OpenStreetMap.Mapnik as default. Will post the next days with update on awesome icons...
  25. That's true. But if your instruction go something like: "You need to include these 4 scripts in your head tag to make this module work and you need to download them from these 4 different places first", it may drive people off. Imagine a developer who cares about page loading optimization and he cannot do it right because of your module. Or he has to go and alter the module code so it fits his needs. Wouldn't it be better if the module followed commonly accepted best practices and people who use the module don't need to care about things like manual script inclusion? I personally don't feel really comfortable with the proposed approach 3, too. The $this->config->scripts->add() method seems to be the preferable way to go. But then you need to instruct the users of your module to include the necessary php for rendering the scripts tags before </body>. Which I consider to be a PW best practice anyway when it comes to conditional loading of scripts. The only point that I really wanted to make is that we should follow best practices and include our scripts at the end of the page and not in the head. If this limits developers freedom, it at least forces something on them that is generally a good thing.
×
×
  • Create New...