Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/12/2025 in all areas

  1. This hook is used to monitor file changes and page updates in your ProcessWire project. It operates when debug mode is active and returns file changes and latest page update information in JSON format. The script hook is automatically injected before the </body> tag in your HTML. It periodically checks for any file or page updates in your system at the interval you specify. If the previous check time is older than the new check time (indicating changes), the page automatically refreshes. ~/site/ready.php if ($wire->config->debug) { $wire->addHookAfter('Page::render', function (HookEvent $event) { $script = <<<HTML <script> const browserSync = { mtime: 0, init() { this.sync(); }, sync() { fetch('/browser-sync') .then(response => response.json()) .then(data => { if (!this.mtime) { this.mtime = data.max; } else { if (data.max > this.mtime) { location.reload(); } } }); } }; browserSync.init(); setInterval(() => browserSync.sync(), 2500); </script> HTML; $event->return = str_replace('</body>', "{$script}</body>", $event->return); }); $wire->addHook('/browser-sync', function (HookEvent $event) { $wire = $event->wire(); $root = $wire->config->paths->root; $siteRoot = $wire->config->paths->site; $extensions = '*.{php,js,css}'; $paths = [ "{$root}src/{$extensions}", // custom composer package "{$root}src/src/{$extensions}", // custom composer package "{$siteRoot}{$extensions}", // ready.php, init.php, finished.php "{$siteRoot}classes/{$extensions}", // page classes "{$siteRoot}templates/{$extensions}", "{$siteRoot}templates/*/{$extensions}", "{$siteRoot}templates/*/*/{$extensions}", "{$siteRoot}templates/*/*/*/{$extensions}", "{$siteRoot}templates/*/*/*/*/{$extensions}", ]; $files = []; foreach ($paths as $pattern) { // Try with GLOB_BRACE first $result = glob($pattern, GLOB_NOSORT | GLOB_BRACE); // If no results with GLOB_BRACE, try without it if (!$result) { $result = glob($pattern, GLOB_NOSORT) ?: []; } $files = array_merge($files, $result); } $filemtime = 0; foreach ($files as $file) { if (!is_file($file)) { continue; } try { $mtime = @filemtime($file); if ($mtime && $mtime > $filemtime) { $filemtime = $mtime; } } catch (\Exception $e) { continue; } } $latest = $wire->pages->get('sort=-created|-modified'); $latestTime = $latest->modified > $latest->created ? $latest->modified : $latest->created; header('Content-Type: application/javascript'); echo json_encode([ 'max' => max($filemtime, $latestTime), 'mtime' => $filemtime, 'modified' => $latest->modified, 'created' => $latest->created ]); exit; }); } This development tool helps streamline your workflow by automatically refreshing the browser when you make changes to your files or content, eliminating the need for manual page refreshes during development.
    2 points
  2. Thx for sharing! In case you don't know or anybody is interested in alternatives: RockDevTools is free and provides asset merge/minify plus live reload:
    2 points
  3. Hi πŸ™‚ Is it possible to have the file upload path to be /site/assets/files/thing.png (or even something custom like /uploads/thing.png ?) instead of /site/assets/files/12345/thing.png ? Thanks!
    1 point
  4. Hi @DrewPH Put the following line into your config.php $config->dbInitCommand = "SET NAMES '{charset}', time_zone = '-08:00' "; Adjust the timezone according to your need. Gideon
    1 point
  5. @bernhard Yes, I know about it. However, I prefer not to use modules for these kinds of things, as my work approach would need to adapt to each module used. I am using Vite for these purposes instead. Before developing this script, I was using the AllInOneMinify module for ProcessWire. Later, I switched to JavaScript-based compilation solutions: First moved to Gulp with Browser Sync Then migrated to Webpack Currently using Vite Among these tools, Vite has proven to be the lightest solution, and I'm getting exactly the results I want with my Vite configuration. While using Vite, I wondered "Why don't I implement my own browser sync solution?" This led me to write this lightweight script, which works remarkably well. And I'm happy with this setup!
    1 point
  6. A very quick and easy solution would be to add css like this to your admin.less file: li.Inputfield_tmp2 input { margin-top: 30px; } Before: After: You need to adjust the field names in your css though.
    1 point
  7. Thanks! *ahem* PHAT stack πŸ˜† It satisfies so many requirements and is a pleasure to work with. It has also been a gamechanger with RockPageBuilder. I've already moved onto my next project and having self-contained blocks with Alpine requiring no external JS makes reusing code trivial. I may create some Github gists together or a repo for easier reuse and sharing. Modals, maps, video embeds- all write once and reuse. I'll check this out. Modernism Week is a long-term retainer client and they're true passionate architecture enthusiasts. I'm trying to keep up with all the knowledge and this might be a nice shortcut 😎
    1 point
  8. Very cool. You got the "PATH" stack going there too (ProcessWire, Alpine, Tailwind, HTMX). Nice. Funny enough, I happened to watch this video on YouTube about the history of Palm Springs architecture.
    1 point
  9. Hi @Robin S - I have tweaked things in the latest commit to make the tabs a little taller so that the tab labels are further from the code which I think helps, but I have also added the ability to switch to a light theme if you prefer (in the Console settings). If you still don't like the light theme option, feel free to tweak it, or submit a PR with an additional theme option if you'd like. Hope that helps.
    1 point
  10. Sorry everyone, I just realized there's a dedicated case studies under the showcase section of the forum πŸ€¦β€β™‚οΈ
    1 point
  11. @adrian, not sure what others think, but personally I like this style of tabs... ...more than the style in recent updates. In the previous version it's clearer that they are tabs, whereas in the newer version I find it all blends in with the code window. Maybe if the tab bar had a lighter background colour so it's more distinct?
    1 point
  12. Quick update- previously Plates for ProcessWire required that you manually install plates via Composer. The module now comes pre-packaged with Plates. If you have already installed Plates via Composer or prefer to do so, this module will prioritize the version that you have installed. If not, the module will use the version that comes with it. I prefer to manage packages via Composer, but that may not always be the case for everyone and I want this module to be easy to get started with, just like Plates itself, regardless of preference or experience. I have pushed some enhancements and improvements to the functions provided by the custom extensions. Going forward extensions will be focused on bugfixes and nonbreaking changes for stability.
    1 point
  13. It should not be a problem to import the comments via the Processwire API. There is also a thread on how to do this here:
    1 point
  14. Sorry, I told you I was just guessing πŸ˜… It should work using the updated code above. Apparently "owner" needs to be prefixed by the name of the repeater field. This time I have tested it.
    1 point
  15. I don't think that this is true ? Repeater items are just regular PW pages. They are hidden in the page tree somewhere under the admin page. It should then be possible to create a page reference field with a selector like "parent=123,include=all" Where 123 is the id of the page that holds your repeater items. Not sure if the include=all is necessary, just try it without.
    1 point
  16. I added tests for two of my modules, VersionControl and ProcessChangelog, back in the day. VersionControlTests is the more recent project, though I haven't touched or used it in years. There's only one test class in that project, and sadly I'm pretty sure it goes against so many best practices that I probably wouldn't consider it a very good starting point ? While I did use PHPUnit, it wasn't really unit testing β€” more like integration testing. The test class starts from a blank ProcessWire installation with required module files included, installs the module, sets up language support and adds some languages, makes changes to page(s) and after each one checks what was stored in the database, etc. In the end it attempts to restore the site to its original "untouched" condition, so that new tests can be started. In my experience ProcessWire involves so many interconnected parts and processes that creating "good enough" mock data would've been a major pain, and still wouldn't really have answered the question of "does this module work as expected in all supported ProcessWire versions, different operating systems, and different database system(s/ versions)". Of course there's still need for unit testing, but in my case it just didn't seem like the best approach ? As for current testing best practices with ProcessWire, I'd definitely check out Process Nette Tester. And β€” this is very opinionated, sorry in advance! β€” I'd probably steer away from PHPUnit. I mean... I'm sure it's an amazing tool once you really get to know it, but the more I've worked (read: fought) with it, the more frustrated I've become. In my humble opinion it's not particularly developer friendly, and there are too many limitations. Again, this might be a result of using it for wrong type of testing, so take it with a grain of salt. I just feel that there are now better options out there.
    1 point
Γ—
Γ—
  • Create New...