Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

72 Excellent

About a-ok

  • Rank
    Hero Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Page transitions etc and I guess barba is just an alternative to that. I see what you’re getting at but as I’d still have this issue with barba then the issue still stands 🙃
  2. Thanks! Yes I know barba.js but surely I’d have the same issue with updating menus/content outside of what’s changing?
  3. I'm looking for some best practice advice. A standard setup for me is to have a head.inc and a foot.inc and then everything in-between is updated via AJAX calls with some transition. Getting a bit boring but that's currently how it is. The issue I have is most of the time the main site nav/menu, which is in the head.inc, is contextual and will change based on the page being view. This can cause a lot of duplication of code as 1) I write it with PW in PHP so if the page is visited directly it is reflected and 2) I also have to do the same in JS if the page is visited via an AJAX call. You see the dilemma. What I've started to do recently is build a PHP array in an include file for the menu, and also `json_encode` it so I have an array, of the same code, one for PHP to use and one for the JS to use. Something like the below... $menuArray = array(); $menuLeft = $pages->find("template=work|news, sort=sort"); $menuRight = $pages->find("template=clients|about, sort=sort"); if ($page->id !== 1) { $menuLeft->filter("id={$page->id}"); $menuRight->filter("id={$page->id}"); } foreach ($menuLeft as $item) { $menuArray['left'][] = array( 'id' => $item->id, 'name' => $item->name, 'url' => $item->url, 'title' => $item->title, 'x' => '100%' ); // If current page then prepend 'Close' if ($page->template->name == $item->name) { array_push($menuArray['left'], array( 'name' => 'close', 'url' => $pages->get(1)->url, 'title' => 'Close', 'x' => '100%' )); } } foreach ($menuRight as $item) { $menuArray['right'][] = array( 'id' => $item->id, 'name' => $item->name, 'url' => $item->url, 'title' => $item->title, 'x' => '100%' ); // If current page then append 'Close' if ($page->template->name == $item->name) { array_unshift($menuArray['right'], array( 'name' => 'close', 'url' => $pages->get(1)->url, 'title' => 'Close', 'x' => '100%' )); } } // Return JSON for JS (PHP can grab $menuArray directly) $menuJSON = json_encode($menuArray); if ($config->ajax) { echo '<script id="menuJSON">'; echo "menuJSON = {$menuJSON}"; echo '</script>'; } Then in the head.inc loop through `$menuArray` and in the JS loop through, on AJAX changes, `menuJSON`. updateMenu: function(e) { var $header = document.querySelector('header.main'), headerContent = ''; for (var menu in menuJSON) { headerContent += '<ul class="menu --' + menu + '">'; menuJSON[menu].forEach(function(item) { headerContent += '<li data-template-name="' + item.name + '"><a data-ajax data-x="' + item.x + '>" href="' + item.url + '">' + item.title + '</a></li>'; }); headerContent += '</ul>'; } $header.innerHTML = headerContent; } The issue I'm having is I have no idea if this is the best way to work with something like this and wondered if anyone had any input? It also feels weird echo'ing out script tag with PHP then relying on the JS finding it in the DOM. You know? Anyway... I'll put this out there and see what happens 🙂
  4. Thanks, @Robin S The original is saved at JPEG quality 8 in Photoshop. Anything less than 100 in PW, in my experience, messes with the colours so always have to keep it at 100.
  5. Anyone? Am I wrong in thinking that the variations would be smaller in filesize? The original is 2000px wide so there’s no upscale.
  6. Not to my knowledge. I have this in my config.php file: $config->imageSizerOptions('sharpening', 'none'); $config->imageSizerOptions('quality', 100); $config->imageSizerOptions('defaultGamma', -1); And yes just a test 😉
  7. I'm resizing my images for img srcset using a helper function: function getSrcsetImages($image, $variations, $sizes) { $srcset = array(); if (empty($variations)) { $srcsetSizes = array(100, 200, 300, 400, 500, 640, 750, 828, 1024, 1125, 1242, 1280, 1400, 1500, 1600, 1700, 1800, 1920); } else { $srcsetSizes = explode(", ", $variations); } foreach ($srcsetSizes as $s) { if ($s <= ceil($image->width())) { $srcset[] = $image->width($s)->url() . " {$s}w"; } } $srcset = implode(", ", $srcset); echo "src=\"{$image->url}\" data-srcset=\"{$srcset}\" sizes=\"{$sizes}\""; } <img <?php getSrcsetImages($image, null, "auto"); ?> class="--lazy" /> This works in theory but in my assets folder why are the variations, on average, larger than the original? Feels like I should just use one image at this point? Any thoughts on what I'm doing wrong?
  8. Just tried it! Works! Thank you! Including the template in the hook method... is this a new thing?
  9. Do you know if this skips the Page Add step?
  10. Is it possible to skip the Page Add step when creating a child page that fills in both the title and name? I've used the template specific setting https://processwire.com/docs/modules/guides/process-template/ but this still requires the user to set a title. Any thoughts? I thought about using a hook https://processwire.com/talk/topic/13058-set-page-title-automatically/ but this doesn't skip the Page Add step.
  11. Does anyone know what sanitising the images get? I thought `$sanitizer→filename` but then it doesn't lowercase them?
  12. Thanks everyone. Do you think it's possible to filename sanitize a folder of images on my local? I'm guessing that's what @Robin S meant when he said: I'll look into it!
  13. Thanks so much, @Robin S Using Automator for Mac I'm going to open a finder file (the .csv) then run a bash script that would create a folder for each ID and move the corresponding image to that folder. A folder can have multiple images. As the DB is all intact it’s only the image links that are missing so this, in theory, should work. I just need to run something on all the images to sanitize them as PW did when the user uploaded them. Would you say using the API, as you’ve kindly shared, is a better approach and more effective and fool proof? My bash script: cd "${1%/*}" while read line do FolderName=${line%,*} ImageName=${line#*,} mkdir "$FolderName" mv "$ImageName" "$FolderName" done < "$1"
  14. This is slightly related to PW but also in need of some advice/help. I stupidly accidentally managed to rm -rf the LIVE assets folder on a site that has over 2 years worth of data. Let's not go there. I had a cronjob set up every night to back everything up (and keep the latest 7) but the .tar.gz files all error out with truncated tar archive and unexpected end of file I've managed to export off the image fields from the database as .csvs and my plan would be to combine them all into one .csv where you have two columns (ID and image filename). I then have a large unorganised dump of ALL the images but they: Haven't had their filenames sanitised by the PW uploading and Are all in one directory and thus not attached to any page ID My question is... how likely do you think it would be to use PW's API to: Sanitise all the filenames in a directory (and if anyone knows what type of sanitising images use) and Execute some sort of query (I'm on OSX) that would match the filename in the CSV with the filename in a directory (the image dump) and move the image to that folder with the same ID (this is a long shot) Any advice is appreciated.
  • Create New...