Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/24/2020 in all areas

  1. This post covers a few of the bigger updates in ProcessWire 3.0.154 and 3.0.155 on the dev branch. This includes a new function for live replacement of text in core and modules, a new method for creating canonical URLs, and some major upgrades to our $input->urlSegment() method that I think you’ll like! This continues from last week’s post in the ProcessWire support forum about 3.0.154 core updates and includes several new details— https://processwire.com/blog/posts/pw-3.0.155/
    8 points
  2. @jonatan I appreciate your excitement. As I may have mentioned before, the biggest feature of this module is around making a good page building experience for non-technical people and making it easy to setup as a developer. "Page builders" in my opinion lie on a spectrum: On the right end you have things like Webflow which is 100% visual and infinitely flexible (let's put aside the fact that it's also a CMS and remotely hosted). It's an amazing tool, even though I don't use it because it's not how I develop. It's a great system, but requires design skill and you have to make sure you are consistent across the board, stick to a style guide, etc. On the left end you have what I will call section builders. Perfect examples include RepeaterMatrix and ACF Flexible Content field for WordPress. I made a video comparing the two in my WP vs. PW series. This approach was probably the go-to approach from... 2010 to 2015? It's much less "flexible" in that at it's simplest form, a section like "image left, text right" will always be as such and unless there are other sections to choose from, you are stuck with it. In the middle-right you have things like Gutenberg, Elementor, Brizy, etc. This is where most of the development action is, thanks to reactive JS frameworks (same with Webflow). In the middle-left there are tools like N1ED, Froala Blocks and others. The way I see it, ProcessWire is a tool geared for developers, and developers can customize it perfectly for their clients. A big part of this is a good page building experience and (a) after having built dozens of websites with RepeaterMatrix and (b) experimenting with different approaches and (c) trying to respect ProcessWire's way of doing things, I have concluded that the section builder / repeater matrix approach is the way to go. It just needs to be improved a bit. (also, I'm lazy and would never be able to program a visual page builder like the fancy ones out there because my JS skills are embarrassing) First, why do I say it's the way to go? Because it's regular ProcessWire, you can do multi-lingual, while not a big deal for me, PW seems to be a favorite for multi-lingual websites. So that's important. Because they are normal template files, a matrix-type that has been used multiple times can easily be modified by editing the template file (requires the developer obviously). Because it's regular ProcessWire, you can SWITCH from one matrix-type to another and retain your data. This is pretty important. Because they are normal template files, you can technically load them directly on other pages that don't even utilize repeater matrix and just inject your own content. YOU CAN DO DYNAMIC CONTENT!!! Well other page builders are doing this more and more, but with ProcessWire, you can do it much better (I'll elaborate on this another day and how my module will do it). I just don't trust non-technical people to create a good looking page from a bunch of sections by dragging and dropping and having too much flexibility. Fonts being mis-matched, colors all over the place, responsive thrown off. This is why I don't like page builders like Gutenberg, Elementor and the like. They look very sexy in the beginning and might be OK for people with web page creation experience, but it gives too much flexibility and web pages are complicated when you consider responsive design, image sizes, etc. I can use my CSS framework of choice (UIkit of course) instead of whatever internal CSS framework each of those builders relies on. So, what problems do section builders currently have (like RepeaterMatrix)? You cannot "preview" a section in a slick way before you add it. Sure, the matrix-type might be named "text left, image right" among a sea of 20+ other matrix types, but this won't stand out, especially in that smashed together list of matrix-types that you get with RepeaterMatrix. Non-technical people are VISUAL, so getting a preview of what they are about to insert goes a long way. My module has solved that problem as I posted in that above video (it's changed a bit from that video in a much better way). You don't page the benefit of instant feedback of what a section (and overall page) looks like as you populate the content. Again, this goes back to the visual nature of people and the soaring popularity of page builders like the ones I mentioned. Given ProcessWire's strict separation between frontend and backend this also gets complicated because ProcessWire's philosophy is about keeping the two separate. However, the true way around this is to use something like ProDraft's Live Preview feature. At this moment in time, it doesn't autosave + live preview changes to repeater/repeatermatrix items, but I've asked Ryan if he could add this (post is here; not viewable if you haven't purchased ProDrafts). He said it's possible and hopefully one day it will be there. When it does get developed, this in my opinion solves the visual feedback aspect of section builders. As a developer, it's annoying to have to continually re-setup repeater matrix for every site. It's not easy to share the template files across various sites which would be ideal. Also, you have to code your own matrix templates and add all the fields accordingly. As a content editor, you want flexibility in the types of layouts... what if you want your "text left, image right" instead of "image right, text left"? Because you can't physically drag-and-drop those elements, then we are forced in having more section templates that address the most common cases. Therefore my module solves this problem by providing 200+ section templates out of the box (and growing). It also provides an alternative (more visual) interface by which you can register those templates into the repeatermatrix section builder fields all from the admin (none are registered in a fresh installation... you choose what you want, so this avoid bloat). And it feels very to the ProcessWire admin interface (a pet-peeve of mine are plugins in WordPress that have their own garrish, bloaty graphics... example: https://wordpress.org/plugins/wordpress-seo/). The important point here is this: content editors / non-technical people / whatever you want to call them therefore no longer have to worry about dragging-and-dropping layouts, potentially messing things up. My belief is if you provide them with a good set of options, they will find what they need, choose the matrix type and then just focus on the content. ProcessWire's backend is all about having a good content entry experience and the ideas I've played around with have evolved around that concept. We want non-technical people to focus on their content and we as developers should not have to worry if they uploaded a 20mb image, because the matrix template will take care of that. Give me a couple weeks and I'll make a video.
    4 points
  3. Yaaaay! Horray! That's my first! ???? And thanks so much for such instant and helpful reply @kongondo! Still continiusly amazed by this great forum and the amazing people behind the PW community! I'll go file it ? Take care! And have a great weekend! All the best, Jonatan
    4 points
  4. At least this seems to be solved already: https://modules.processwire.com/modules/process-email-to-page/ I have never developed a browser extension myself, but I guess it should not be too hard. The extension could send the URL to your PW and there you could do anything with that request. You just need to make sure to do proper sanitization of the data and that only allowed users can post data to your system (eg. via a secret token).
    4 points
  5. I use the classLoader in my TrelloWire module, you can look at the source code here. As you can see, this adds the src directory inside the module files to the WireClassLoader as the location to look for classes inside the namespace ProcessWire\TrelloWire. Almost; it doesn't preload the classes, but only on demand. This way, once I instantiate the class ProcessWire\TrelloWire\TrelloWireApi, the WireClassLoader looks for the PHP file for this class inside the src directory (the one registered for that namespace through addNamespace). If it couldn't find it, an error would be thrown. (If you're wondering why I don't use the fully qualified namespace, note the use statement at the top). Two main advantages: Using an autoloader, you can map classes to directories. The exact mapping (how namespaces are resolved to file paths) is defined in the PSR-4 standard. As far as I know, the WireClassLoader loosely complies with that. Composer mostly does the same thing (although a bit more elaborate, with optimizations for production usage etc.). Basically, you have a root directory mapped to a root namespace (in this case ProcessWire\TrelloWire -> src/ directory), and from there resolve sub-namespaces to sub-directories and the class name to a file name (so ProcessWire\TrelloWire\TrelloWireApi -> src/TrelloWireApi.php). The advantage is that you add namespaces wholesale. So you only need to add the mapping for the root namespace, and can then add as many classes and nested namespaces and classes without having to worry about including any class files manually because they will be autoloaded. Because class files are only included on-demand, only the classes you actually need for a request will be loaded. This of course cuts down on processing time, since otherwise you'd usually include all classes at the top for every request. Hope this clears up some of the confusion!
    3 points
  6. I can confirm this. Congratulations! you've found a bug :-). Please file a bug report here: https://github.com/processwire/processwire-issues/issues Read this first: https://github.com/processwire/processwire/issues/8
    2 points
  7. Yes, in general all autoloaders work this way. Composer just generates a file that registers an autoloader function through spl_autoload_register. This function is then called whenever a class is used that is not loaded yet, as a last chance to load the class before an error is thrown. Composer has a few different ways of locating the class files though. You can even generate an optimized autoloader that includes a class map which will speed up autoloading a bit. You can also test if a class is loaded already or autoloaded with class_exists: // using class_exists with false as the second argument, the autoloader will not be called // this return false for all classes that have not been manually included or autoloaded yet var_dump(class_exists('Some\Vendor\Class', false)); // this will trigger the autoloader, so even if the previous call returned false this will return true if the class exists var_dump(class_exists('Some\Vendor\Class')); I have a bit more information on Composer usage in my Composer for ProcessWire tutorial ? Personal preference! I do believe that the .module files themselves need to be inside the ProcessWire namespace in order for ProcessWire to correctly load them in all situations. But ProcessWire doesn't know about the files in the src directory, so I could use any namespace I wanted (for Composer libraries, you'd usually use the developer / organization name as the top-level namespace, so I might have used something like MoritzLost\TrelloWire). It just felt wrong to me to have the main module files inside the ProcessWire namespace and the API in an entirely different namespace, this is why I used ProcessWire\TrelloWire.
    2 points
  8. Set this up for the first time tonight, works really well over here. Just to save someone else some head-scratching, if you do this: Consider adding include=all to your selector to also iterate through unpublished and hidden pages when synchronizing your relationships.. // Get all pages where page_field_a is not empty, including hidden and unpublished pages $pgs = $pages->find("page_field_a.count>0, include=all"); ... Great work on the module @Robin S, coming in very handy ?
    2 points
  9. Glad you got it sorted :-).
    2 points
  10. I've just fallen in love with Hubspot (small team so the bundle for more features just for 2 users is worth it, especially since it's discounted for 12 months at the mo). Looking at all the API possibilities - we use RingCentral - that plugs in with a few clicks, can hook Formbuilder form submissions in with very little work, all the social media channels we're setting up right now get linked in including Facebook chat for our new page etc etc. Actually quite excited. But yeah the pricing gets out of hand quickly for larger teams or more contacts when you need over 1,000 on one of the paid plans. It's not without its costs (I want to say hidden costs, but they just require some reading to find) but the way I'm looking at it at the moment when I need to go above the starter packages I should be able to afford it. Hopefully ?
    2 points
  11. Given that your field is named images, I am guessing it is a multi image field. This means the field can contain more than one image. This depends on how you set up the field (see its settings when editing the field. Assuming this is a multi image field, you code above won't work. Speaking in very general terms, there are two types of fields: Ones that return only a single value and ones that return multiple values. For instance, an email field will return only one value; the@email.tld. For the fields that can return multiple items, think about it this way... Imagine you have a basket. The basket can contain several fruits. If someone asked you to "give me the fruit"? Your natural response (assuming you are willing to give;-)) would be "which one"? This is because there are multiple fruits in the basket. By requesting the fruit, it implies they want not just any fruit but a particular fruit. That is the same thing you are asking in your code above; "Give me the URL" and ProcessWire is responding with which one? There are several images here, which one do you want? Back to the images, you will need to either specify which image's URL you want or have ProcessWire return the URLs of all the images in the collection (the field on that page). The latter means you have to loop through the images field (collection) as well. Some code.. foreach ($entries as $entry) { $images = $entry->name_of_your_image_field;// e.g. $entry->logo // we want all images so we loop through the image field foreach($images as $image) { // just an example echo $image->url; } } Edit You access a field of a page using its (the field's) name. @see my edit above ($entry->logo). If the image field is of type single, you don't need to loop through it. Just echo its content, e.g. echo $entry->logo;. In other words, there is no API variable called images in ProcessWire.
    2 points
  12. Wow @Jonathan Lahijani, just wow! ? That's what I call an elaborative answer! ?? I think your analysis is simply just so great! I almost couldn't agree more upon what you're saying! Your spectrumfication of page builders as well as your pros and current-issues overview of the "leftwing" section builders approach is really great! – YES! I personally adore Webflow! I actually came from the Webflow community a while before joining PW. I'm also myself much more of a visual designer ? than I'm actually a developer ?. And also.. Wf is pricy, PW is free & open source! ? I've mostly taught myself HTML & CSS and copy pasting JS back in primary school, which is enough for Webflow, and then since recently joining PW also basic PHP ("necessity is the mother of invention"). Webflow is truly an amazing tool I agree, but as you mention, on the other hand it does require more design skills (though I believe, not having updated myself on Wf that much recently though, that they're constantly improving their CMS experience and templating experience...) HEAR, HEAR!!! AGREE!!! ?? This is what I meant with : – It's great to let the editors gain some creative freedom, but on the other hand, if they're not designwise nor technically skilled, whichever beautiful design you've created, you'll see them make it fu***** ugly!... Before PW, before Wf, I was using the very basic (though it had CSS and HTML editing...) site builder Weebly. This problem you describe would exactly be the case. Because whatever you'd have designed, the editor (not being neither designer nor technically skilled) would simply (with good intentions though) make it ugly! Because they are simply given too much freedom, more than what's good. Then talking about the kind of slightly (only just slightly) more sophisticated solutions , you have Elementor, as you also mention. Recently I built a site in Elementor. And what a pain!.... Building slightly more advanced templates and custom functionality and design features directly in the Elementor editor is way much more "hacking" and so so so much "fixing" (in general applies to all of WP) more than it's actually developing or designing. The idea is good. The reality is.. not so good. Talking about this... Would the amazing module that you're building also be interchangeable in regards to CSS framework wise, say able to – easily – use Bootstrap instead of UIkit? Perhaps even somehow built in? All in all though I just can't wait to see this! I'm very much looking forward for your video. And again, any kind of sneak peeks or even some beta demo would be highly highly appreciated! All the best, Jonatan
    1 point
  13. For others reading this, the new location of these docs is: https://processwire.com/docs/start/install/troubleshooting/
    1 point
  14. That is a real eye opener Pixrael and really puts it into perspective. Most of my clients who use a combination of PW/SnipCart are turning over much less, so at present it's an affordable solution. If I'm lucky enough to work with clients with that level of sales volume I'll no doubt be shying away from SnipCart. I understand they do offer some negotiation on fixed fees for high volume stores but they don't share publicly what kind of fee that might be.
    1 point
  15. I don't think that is what is being recommended here :-). The expressed need in OP was for admins (e.g. editors, trainers, teachers) to be able to view list of students' ratings, registered students, etc in a unified interface.
    1 point
  16. Hi @kongondo I did not find a solution to this until now. I think there is none in general. InputfieldCkeditor has a custom implementation for that need var editor; if(typeof ProcessWire.config[configName] != "undefined") { var editor = CKEDITOR.replace(editorID, ProcessWire.config[configName]); } else if(typeof $editor.attr('data-configdata') != "undefined") { // allow for alternate option of config data being passed through a data attribute // useful for some dynamic/ajax situations var configData = JSON.parse($editor.attr('data-configdata')); ProcessWire.config[configName] = configData; var editor = CKEDITOR.replace(editorID, configData); } if(editor) { ckeInitEvents(editor); $editor.addClass('InputfieldCKEditorLoaded'); } So with CKEditor you can pass through custom settings via data-configdata. But that's also only related to the display part of the Inputfield. Regarding ajax processing on the backend I have not found any other way than setting the values directly in the DB (meaning to create a dedicated field for every different setting). I have not looked into how the template overriding feature for fields works. Maybe there is some hookable method that could be used to modify the settings based on the template just via code? https://processwire.com/blog/posts/pw-3.0.145/#field-template-context-override-settings If you find anything please let me know ?
    1 point
  17. I see you put TrelloWire within the namespace of ProcessWire. Is there any benefit or is that just a matter of taste?
    1 point
  18. Way better with Processwire, since all you need to handle is content management.
    1 point
  19. Yes, RockLESS can send variables from PHP to LESS: $less = $modules->get('RockLESS'); $less->vars = [ 'foo' => 'bar', ]; $css = $less->getCSS($config->paths->templates . 'less/theme.less')->cssUrl; echo "<link rel='stylesheet' type='text/css' href='$css'>"; How you combine that with ProCache is up to you. You can either send the compiled CSS to procache or I think you could also generate a LESS file via plain PHP listing your variables and include that file via @include in your LESS and then parse that LESS via ProCache.
    1 point
  20. It always depends on what you want to do with the system. If you only want to create single pages with text and a blog, then Wordpress might be the right choice. However, if you want to create customized pages with specific functions, tailored to a customer or a project, Wordpress gets very complicated. This is where Processwire can make the most of its advantages: - easily extendable - the edit surfaces are almost perfectly adapted to the pages - high-level flexibility But to use Processwire, you need to know HTML and PHP. But if you want to use Wordpress not only with ready-made themes and modules, you need the same knowledge. In my opinion Processwire is even easier.
    1 point
  21. I am not a web developer pro, but I understand that a (piece of) code or a (programming) concept can be "beautiful". If you make yourself familiar with Processwire, you will find such very often.
    1 point
  22. That depends on the store, if the monthly income is in the order of $20,000, the fee for using Snipcart is $400.. but in more quantities, it will go crazy. In one of the stores that I manage (Check the picture), so far this month (and there are 8 more days) the Snipcart charges would go up to $16,658, but Shopify only charges me $266 for the whole month. It would be very interesting to have a similar module for Shopify, or better for a headless ecommerce patform like https://saleor.io/ PS: Source https://github.com/mirumee/saleor Store example https://pwa.saleor.io/ Admin https://pwa.saleor.io/dashboard/ Login credentials: admin@example.com / admin
    1 point
  23. I only have one kid, so in some ways that keeps things easier, although she's in the office with me on the other PC which can make things interesting at times. We are allowed out walking as long as we keep to our neighbourhood and stay a safe distance from other people. Things have been pretty relaxed up until Sunday when the oven died, which made things a bit more inconvenient as we've been doing a lot of home baking, but that is out of the question now until I can get someone to repair it, or buy a replacement, which either way looks like at least a week away. At least there's a good chance of eliminating the virus completely here within the next few weeks, which will allow life to return to some semblance of normal, but the borders will likely be closed well beyond the end of the year.
    1 point
  24. @Pete From this side, my wife's job is one that requires her to be on phone/video meetings most of the day, so she's got to lock herself away from us to focus on that, and the kids are mostly with me during the day. I'm good at focused attention, but not great at changing gears, so I'm still learning. My days used to be just coffee and code. Now things are much more diverse, here's a typical day: wakeup, breakfast, coffee, code, kids wakeup, resolve dispute, make breakfast, coffee, code, hear that TV is on, check in to make sure kids are doing school work, turn off TV, say “get back to school work”, try to figure out something with google classroom, worry about whether I'm doing enough to keep kids focused on school, code, get icloud request to approve download of some game on iPad, tell kids to “get back to work”, explain why several times, answer questions about school work, hear music from some game and decide to let it slide, 1 email, cycle power on router because wife says she can't connect to important video call, code, resolve kids dispute, put 1 kid in timeout, legos, clean up spill, 1 email, slack message, cook lunch, coffee, code, worry about whether kids are spending too much time on screens, phone call, reset wifi because daughter says Roblox won't connect, then work a little more, click the "snooze" button on a dozen emails so they return tomorrow, take kids outside to play while I work on house or yard, ride bikes, cook dinner, eat, netflix, cleanup dinner, go to bed, feel thankful to be healthy, sleep well. I'm definitely still adapting here, but I can't complain about the new normal because having everyone under one roof is comforting, especially at times like this. And while it's harder to get work done, it's mostly still getting done and I just feel thankful to be staying busy. Also, knowing there's nowhere to go but home, life is simpler in many ways.
    1 point
  25. In a template $page is the current page that your visitor has requested and is being output for them. $pages gives you access to all pages in the system by calling methods like $pages->find() or $pages->get(). “Child” is only one child. When you call $page->child() it will give you the first child. If your page has multiple children, you may want all of them. That’s when you call $page->children(). If you want only some children, you can pass a selector to the method. See the docs herehttps://processwire.com/api/ref/page/child/ and here https://processwire.com/api/ref/page/children/. “Render” usually implies that the method generates markup aka HTML code for you. When you use get() you simply get the thing you asked for. It may be a Page object or the contents of some field or something else, depending on the context. ProcessWire has the concept of “Output Formatting”, which means that field values can sometimes also generate/contain markup themselves, without the word “render” showing up anywhere. So it’s not all that clear cut, but that’s the basic idea. ”Rendering“ means taking something that can’t be output to the browser directly and formatting it, usually as HTML. Sometimes ProcessWire makes its features available to you as properties AND as methods. This can be convenient but also confusing. You’ll have to consult the docs for each individual case, or just test out what works. If you want to pass arguments/options, you must use the function way. If you’re not familiar with the concepts of properties and methods/functions, perhaps familiarize yourself with PHP basics before reading the ProcessWire docs, or just read the PHP docs as you go along. Or ask in the forums here, PW has an exceptionally friendly community. Welcome to ProcessWire ? Edit: To answer your actual question, you cannot do $page->children->image->url, because children is a PageArray. It's a way to collect multiple pages, in this case all the child pages of $page. So when you call children->image, it doesn't know which child page to take the image from. You could do $page->child->image->url. That would give you the image from the first child page. Be aware that there may be no children, or the first child may not have an image. These cases may need to be considered as your website grows.
    1 point
  26. My module is going through quite a bit of evolution, almost on a daily basis, as I build more sites with it. It will probably be ready sometime this summer, including documentation and a website. It's quite complex, but very thorough. I've built about 10 sites with it so far, with each site providing various insights and feature ideas that make it into the module.
    1 point
  27. Probably I don't have any rights to comment how far PW came since I started using it from the version 2.x. Of course it is hard to balance and I perfectly know what is mixing MVC and framework and CMS. If they ever listened me (in that time I came from the country which had bad reputation for leading the war against neighbors) Joomla! would stay on top of WordPress. For years Joomla! didn't do anything about SEF URLs and it costed that CMS so much. And it was so small effort and thing to do. Please, think about it. Now, for two years I didn't touch any other CMS except PW and I am very very happy like never before and I am not developer.
    1 point
  28. So true. I already begged for this years ago . . . However it is not happening. Processwire already has become over-engineered and keeps on getting stuffed. Status Quo mind set also rules over Processwire.
    1 point
  29. The main magic is You don't have to install any module to have media manager. There is a bunch of options. Make template "gallery", put all images on that page. Call images via tags or Page Reference or whereverver model you want. That flexibility and finding the best possible model makes me speechless. The thing is, PW is not a pure CMS and it should stay that way. This is so good I can't believe it exist. Kudos to Ryan and team!!!
    1 point
  30. I also came from Joomla and was so happy to discover ProcessWire. It was a game changer for me. The good thing about PW is, that you can have all these things on demand as modules. So it is up to the developer to choose features they want to include on a site.
    1 point
  31. WOW. This is very impressive. Gideon
    1 point
  32. Woah... Well... I don't use this word that often but... this is insane. In a very good and positive way.
    1 point
  33. It will be free, open-source, like other starter tools out there.
    1 point
  34. There are predefined system permissions for this - you just have to install them: https://processwire.com/docs/user-access/permissions/#page-edit-created https://processwire.com/docs/user-access/permissions/#page-edit-trash-created
    1 point
  35. Just a note, better to update the recipe code to: if($page->template=="admin" && $page->parent->id==2 && $page->name=="settings") $input->get->id = $pages->get("/settings/")->id;
    1 point
  36. Go to Modules > Core > AdminThemeUiKit. You can choose the Gravatar option or you can edit the user template to add an images field which can be used for manually added images. Remember that the user template is a system template so you need to go to Setup > Templates > Filters > Show System Templates.
    1 point
  37. I would also like sqlite for reasons of easier local development and portability.
    1 point
  38. Update 2018-07-09: ProcessNetteTester module is available in the Modules Directory and on GitHub. This is a short tutorial on how to use Nette Tester with ProcessWire. As you will see it's very easy to setup and use and it's perfect for testing your code's functionality. With bootstrapping ProcessWire it's also possible to check the rendered markup of pages using the API, checking page properties, etc. It's also a great tool for module developers for writing better code. While there will be nothing extraordinary here that you couldn't find in Tester's docs this can serve as a good starting point. Prerequisites: PHP 5.6+ 01 Download Tester Go to https://github.com/nette/tester/releases and download the latest release (currently 2.0.2). Download from the link reading "Source code (zip)". You can use composer also if you wish. 02 Extract Tester files Create a new directory in your site root called "tester". Extract the zip downloaded here, so it should look like this: /site /tester/src /tester/tools /tester/appveyor.yml /tester/composer.json /tester/contributing.md /tester/license.md /tester/readme.md /wire ... 03 Create directory for test files Add a new directory in "/tester" called "tests". Tester recognizes "*.Test.php" and "*.phpt" files in the tests directory, recursively. 04 Create your first test In the "tests" directory create a new "MyTest.php" file. The first test is a very simple one that bootstraps ProcessWire and checks if the Home page name is "Home". This is not the smartest test but will show you the basics. Add this to "/tester/tests/MyTest.php": <?php namespace ProcessWire; use \Tester\Assert; use \Tester\DomQuery; use \Tester\TestCase; use \Tester\Environment; require __DIR__ . '/../src/bootstrap.php'; // load Tester require __DIR__ . '/../../index.php'; // bootstrap ProcessWire Environment::setup(); class MyTest extends TestCase { // first test (step 04) public function testHomeTitle() { $expected = 'Home'; // we expect the page title to be "Home" $actual = wire('pages')->get(1)->title; // check what's the actual title Assert::equal($expected, $actual); // check whether they are equal } // second test will go here (step 06) // third test will go here (step 07) } // run testing methods (new MyTest())->run(); I've added comment placeholders for the second and third tests that we will insert later. 05 Run Tester Tester can be run either from the command line or from the browser. The command line output is more verbose and colored while in the browser it's plain text only (see later). Running from the command line Navigate to the "/tester" directory in your console and execute this: php src/tester.php -C tests This will start "/tester/src/tester.php" and runs test files from the "/tester/tests" directory. The "-C" switch tells Tester to use the system-wide php ini file, that is required here because when bootstrapping ProcessWire you may run into errors (no php.ini file is used by default). You may load another ini file with the "-c <path>" (check the docs). If the title of your Home page is "Home" you should see this: If it's for example "Cats and Dogs", you should see this: Running from the browser First we need to create a new PHP file in ProcessWire's root, let's call it "testrunner.php". This is because ProcessWire doesn't allow to run PHP files from its "site" directory. The following code runs two test classes and produces a legible output. IRL you should probably iterate through directories to get test files (eg. with glob()), and of course it's better not allow tests go out to production. <?php ini_set('html_errors', false); header('Content-type: text/plain'); echo 'Starting tests.' . PHP_EOL; echo '--------------------------' . PHP_EOL; $file = __DIR__ . '/PATH_TO/FirstTest.php'; echo basename($file) . ' '; require $file; echo '[OK]' . PHP_EOL; $file = __DIR__ . '/PATH_TO/SecondTest.php'; echo basename($file) . ' '; require $file; echo '[OK]' . PHP_EOL; echo '--------------------------' . PHP_EOL; echo 'Tests finished.'; exit; Navigate to "DOMAIN/testrunner.php" in your browser to execute the file. If every test succeeds you should get this: If there are failed tests the execution stops and you can read the error message. If there were more tests (eg. ThirdTest), those won't be displayed under the failed test. 06 DOM test This test will check if a page with "basic-page" template has a "h1" element. We will create the page on the fly with ProcessWire's API. To keep things simple we will add the new test as a new method to our MyTest class. Add this block to the MyTest class: public function testBasicPageHeadline() { $p = new Page(); $p->template = 'basic-page'; $html = $p->render(); $dom = DomQuery::fromHtml($html); Assert::true($dom->has('h1')); } This will most likely be true but of course you can check for something more specific, for example "div#main". Note that we have used the DomQuery helper here (check the "use" statement on the top of the file). 07 Custom function test You will probably want to make sure your custom functions/methods will work as they should so let's write a test that demonstrates this. I don't want to complicate things so I'll check if the built-in "pageName" sanitizer works as expected. Add this to the myTest class: public function testPageNameSanitizer() { $expected = 'hello-world'; $actual = wire('sanitizer')->pageName('Hello world!', true); Assert::equal($expected, $actual); } This should also be true. Try to change the expected value if you are eager to see a failure message. 08 Next steps You can add more methods to the MyTest class or create new files in the "tests" directory. Check out the range of available Assertions and other features in the docs and see how they could help you writing more fail-safe code. Once you make a habit of writing tests you'll see how it can assist making your code more bulletproof and stable. Remember: test early, test often ? If you find out something useful or cool with Tester make sure to share.
    1 point
  39. You can change label field globally in the setting of ProcessPageList module - {title} | {template.name}
    1 point
  40. Although I don't believe this is would be coming any time soon, I'd just like to leave a note here that I would really really really enjoy sqlite for processwire very much. It would be so much easier to handle and synchronise smaller sites just by version controlling the files of the project. *sigh* ... could the FileCompiler offer a new approach on creating a universal compatibility especially for 3rd party modules?
    1 point
  41. as there is really no difference between those two modules it's definitely better to stay with robin's version. thank you @Robin S for your hint to ->add()
    1 point
  42. I also hate empty paragraphs so gave this a try. Works well for me. This is an interesting one. There is a setting, but it doesn't work as intended. With the help of Tracy Debugger I did a bit of investigating as to why but haven't got to the bottom of it yet. The line intended to replace empty paragraphs in InputfieldCKEditor is this: $value = str_replace(array('<p><br /></p>', '<p> </p>', '<p></p>', '<p> </p>'), '', $value); But it doesn't match the empty paragraphs because $value has already passed through HTML Purifier where gets replaced with some mystery space character. So neither 'nbsp;' nor ' ' match the space character between the paragraph tags. I haven't been able to work out what this space character is because it's rendered like a normal space in the variable dump. --- Update: the mystery character is a UTF-8 encoded non-breaking space character. So the code above should instead be: $value = str_replace(array('<p><br /></p>', '<p> </p>', "<p>\xc2\xa0</p>", '<p></p>', '<p> </p>'), '', $value); Double quotes are needed around the string with the UTF-8 non-breaking space. I'll submit a pull request for this fix.
    1 point
  43. Oh yes! This would be downright amazing. Because convenience.
    1 point
  44. Uh, yeah... I'm really interested in what we will end here Btw: There's a good readup about its implementation limits https://www.sqlite.org/limits.html
    1 point
  45. I think there's no problem with shared hosting involved here. But: - A big advantage using SQLite is moving/replicating a site to a different server/domain (you name it). - Also updating to new contents is a matter of replacing one file (the .db file itself, without the need of messing with a server). - And last, not least, it's pretty convenient in a development environment, since you can run your dev-tools without cluttering your local backend with databases. just my 0.02
    1 point
  46. +1 Using SQLite would be the killer for PW (at least for me). Any info *IF* this will ever happen? thx andy
    1 point
  47. I think a sqlite compatibility would be fantastic for smaller sites. It is so common to be working on a client's shared host to find mysql running painfully slow. In contrast, sqlite will respond instantly. Drop http://getcockpit.com/ into a sluggish shared hosting environment and watch what happens.
    1 point
  48. I'm new to PW and just creating my first website using it, but was courious if I could use SQLite. The reason is deploying websites would be much easier and faster (no database setup required). For small websites it would be perfect, just copy & paste and you are ready. It would then compete with ie GetSimple CMS with simplicity of deployment (that I found about from this forum) but would be much more powerful. And great for having very fast to deploy templates. I believe a lot of people that are creating html templates, having no PHP/MySQL skills, could use it, as it would be so easy and fast to do. Some slogans from other CMSs that could apply to PW then: "add content management to any site in five minutes" "just copy to server and start using" I see that WolfCMS had support for SQLite as a plugin and now it has been bundled with the core. I am not knowledgable about PDO, just read little bit about it, but maybe it would be good idea if it was possible? It would support many databases and be more future proof?
    1 point
  49. 1 point
  50. I'm using SQLite for my own programming, it's a very nice little tool. Wouldn't hurt to have it as an option, in fact I've been wondering for long why we have to use such a monster as MySQL when 95% and more of the time, something like SQLite would be enough. But that's an extra-work and PW probably a lots of more important stuff to do before thinking to convert to SQLite... What would be nice though is that you keep PW "as compatible as possible" so that one day - when the list of priority improvements my be empty - it will be "easily" possible to adapt.
    1 point
×
×
  • Create New...