Jump to content

JayGee

Members
  • Posts

    278
  • Joined

  • Last visited

Everything posted by JayGee

  1. Oh sorry you got me!! I was originally going to post two threads for the slightly different (but related) issues. But shortly after posting I fixed one of them and as nobody had seen or responded to it yet (or so I thought) I edited it into one post... but you must have responded at the same time. Apologies ?
  2. @joshua this looks like a really useful module thank you ?. Will definitely be giving this a try on our next project.
  3. Thanks @Robin S - although, not sure if I'm being thick here ?, but will that change anything on the specific problem of the final image's description not being updated? The rest of my loop seems to work fine, but for some reason it doesn't apply the description to the final image/iteration. Really odd.
  4. This short script loops through some images from an XML feed and pushes new ones to an image field. It all works perfectly, except for some reason the last image (only) in the loop each time doesn't receive the image description... can everyone spot why? TIA! ? foreach ($propertyImages as $img) { $fileName = trim($img[0]); if ( !empty($fileName) ) { $imgPath = '../property_data/'.$fileName; if(file_exists($imgPath) && !in_array(strtolower($fileName),$currentImages)) { $p->property_images->add($imgPath); $p->save(); $newImg = $p->property_images->last(); $newImg->description = $img[1]; $p->save(); } } }
  5. Ok got it - this works! $ogImg = $page->single_image->first()->httpUrl; So as you said @gebeer it's something to do with the images being stored in an array, but no idea why looping through them manually wasn't working!
  6. Yes have tried both as a method and property.
  7. I'm not getting the memory error now, I've changed the page save to target the specific field and this seems to hugely improve performance. Pageimages being an array makes sense, but looping through the image field isn't working either. In actual fact when I start logging the output on save as I go it just seems httpUrl() isn't returning anything whereas url() does. It's because the site is running markupSEO module to handle OG and meta on all other pages. Only on this specific page type I just want to auto populate the OG image field so they can go on using the rest of the module functionality elsewhere.
  8. I've written a very basic hook script with the aim of updating one field with the value from another on page save. I want to get the full absolute URL of an image to populate an OpenGraph image tag field. If I change the url() call on single_image to httpUrl() I get a server memory exhausted error. I'm certainly not a PHP wizard but I don't think this should be particularly taxing. Have I accidentally created a loop somewhere? Calling url() works fine. Running ProcessWire 3.0.141. <?php //Hook page save to update Open Graph Image URL with featured image $wire->addHookAfter("Pages::saved(template=article)", function ($event) { //Get which page has been saved $page = $event->arguments(0); //Check featured image is set if ($page->single_image) { $ogImg = $page->single_image->url; updatePage($page,$ogImg); } else { $ogImg = 'https://examplesite.co.uk/site/templates/images/default-og-img.jpg'; updatePage($page,$ogImg); } //$message = "Open Graph image successfully generated"; //$this->message($message); }); function updatePage($page,$ogImg) { $page->seo_image = $ogImg; $page->save(); }
  9. Interesting - I did try to call setLocation() from ready and init and both threw an error even though the blog post indicates they’re callable from there.
  10. That was my first thought too but it seemed to produce different output when bootstrapped vs loading as ‘native’ ProcessWire. Although I’ve now solved it, my hunch is still the rewritebase option in htaccess wasn’t working as intended. It could be because of the NGINX Apache proxy setup. For the record since I left the office for the day it dawned on me that the link @wbmnfktr posted above to Ryan’s updates on the customisable paths probably will work - but I think it may currently require the dev branch whereas this site is running master.
  11. Ah ha moment - I think I got it! Setting the root url in the template seems to have solved the issue. Although I think as per your post @wbmnfktr there's possibly a less destructive/repetitive way to this in future if can get my head round it! <?php $config->urls->root = '/pw/';?>
  12. Thanks @wbmnfktr - I did take a look at this and couldn't get anything working. I'm not sure at this stage if this is a server config issue my end or I'm not using ProcessWire as intended in this scenario. It seems to me that PW is grabbing site root from the parent page where the embedded bootstrap content is rather than the PW installation itself. Is this expected behaviour?
  13. Have read loads of similar threads but can't find the deifnitive answer. I'm bootstrapping ProcessWire into a Magento installation. Everything is working fine in terms of expected PW API functionality, however I cannot get the paths for images in the site work correctly. ProcessWire is installed in a subfolder called 'pw'. If I load the PW site directly e.g. visit mainsite.com/pw everything loads fine and all image paths are correct. If I load the parent site in the root folder with the PW bootstrapped page content rendered within it, the image paths don't contain the subfolder and so are broken. So I get https://mainsiteexample.com/site/templates/img/test.jpg instead of https://mainsiteexample.com/pw/site/templates/img/test.jpg I've tried updating the rewrite base in the .htaccess file but it doesn't seem to make any difference. Have also tried various settings in the config file to no avail. Wondering if rewrite base perhaps isn't working as intended because I'm behind a NGINX/Apache hybrid environment?
  14. Thank you - I knew I was doing something stupid... burning the midnight oil!
  15. I've created a simple sports league fixture generator in a template called 'League'. Teams are added as page references then a fixture list is created as a ProFields table by hooking page save to add new rows to the table. The bit I need help with is that I'm trying to check a fixture doesn't already exist before adding it to the table (e.g. if a new team is added to the league). I'm trying to do this with a PW selector to filter the fixtures table and check whether Team A vs Team B already exists in the table. Then on the next line checking no fixture was found by using count(). However as soon as I add the selector the script no longer adds any rows to the table. If I take it out, it all works fine (albeit with duplicate fixtures each time the page is saved). I've also tested the selector in a page template and it filters as expected. It's late here (UK)... I'm probably doing something stupid! Any ideas? <?php //Hook page save to generate league fixture lists $wire->addHookAfter("Pages::saved(template=league)", function ($event) { //Get which page has been saved $page = $event->arguments(0); $noFixturesAdded = 0; //For each team in league cycle through and add home fixtures foreach ($page->teams_in_league as $teamA) { foreach ($page->teams_in_league as $teamB) { //Check if fixture already exists $existingFixtures = $page->fixtures("team_a=$teamA,team_b=$teamB"); //Check team A is not the same as team B as you can't play yourself //Then add row to fixture table if ($teamB != $teamA && $existingFixtures->count() < 1 ) { $fixture = $page->fixtures->makeBlankItem(); $fixture->team_a = $teamA->id; $fixture->team_b = $teamB->id; $page->fixtures->add($fixture); $noFixturesAdded ++; } } } //Save updates to table $page->save('fixtures'); $message = "League saved. $noFixturesAdded new fixtures were added"; $this->message($message); });
  16. Thanks @Ralf - can confirm this solved the title issue. Still had some issues with importing multiple page refs which I worked round with a quick custom JSON import script, but good to know can use this import going forward.
  17. Hi @Ralf - thanks for this - completely missed Reno's note but this sounds like my exact issue and will try it out today.
  18. Is it possible to import users with this module? When I try I get the error Unable to import page because it has no required 'title' field or it is blank. If I add a title column to the CSV it doesn't show on the next page. I simply get a 'title' select field to map it like the other field but no title field shows in the in the dropdown.
  19. Just to double check - did you enable page numbers in the page template settings?
  20. I think I did - but will double check as got frustrated and parked it for later on lol! I think it was causing strange things like the item still showing in the repeater without affecting the on/off toggle and then re-enabling when the parent page was saved. Will give it another go and report back.
  21. Thanks all - that does all seem a bit of a headache - it's not mission critical so will probably just stick with deleting unused items rather than disabling them or just let the user manually manage them. Had naively assumed that as repeater items were pages behind the scenes that the 'toggle' would just be a proxy for unpublishing them or something similar.
  22. Yes I think you're right! Thank you!... that was driving me crazy!
  23. I think it could be because you are also using url segments. You can set the base URL for the page to be paginated when calling the pager. I can't seem to find the relevant docs at the moment but this is a snippet from a project I have open at the moment that I recall has the same issue that hopefully shows the syntax you need. $pagination = $articles->renderPager(array( 'baseUrl' => '/sector/'.$currentCat.'/' ));
×
×
  • Create New...