Jump to content

JayGee

Members
  • Posts

    247
  • Joined

  • Last visited

Posts posted by JayGee

  1. 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.

  2. 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();
                    }
    
                }            
                
            }

     

  3. 42 minutes ago, gebeer said:

    I think, the problem is with $page->single_image being of type Pageimages, not Pageimage.

    Inside hooks the $page object's output formatting is turned off. This means that even for image fields that are defined to hold only 1 image, the field is of type Pageimages, which is an array.

    You can confirm this by doing var_dump($page->single_image) (or better using Tracydebugger bd($page->single_image)).

    So to get to the actual image, you need to loop over the Pageimages array like

    
    foreach($page->single_image as $image) {
    	// your logic goes in here
    }

     

    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.

    32 minutes ago, wbmnfktr said:

    Why in a hook and why saving the image to another field and so on?

    Why not just checking it in the template and outputting different values for OG/SEO?

    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.

  4. 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();
    
    }

     

  5. 17 hours ago, matjazp said:

    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.

  6. 42 minutes ago, dragan said:

    Can't you just use httpUrl instead of url?

    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. 

  7. 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?

  8. 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?

  9. 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);
            
    });

     

  10. 9 hours ago, Ralf said:

    @Guy Incognito

    did you do everything renobird wrote in his post on page #4 of this thread?
    In particular "... In order for title to show as a connection option during your import, you need to add the title field to the user template file. ..."
    http://processwire.com/talk/topic/383-module-import-pages-from-csv-file/?p=10160

    For me the import works, I just edited ~200 users.

    Hi @Ralf - thanks for this - completely missed Reno's note but this sounds like my exact issue and will try it out today.

  11. 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.

  12. 5 minutes ago, adrian said:

    Did you try:

    
    $item->addStatus(Page::statusUnpublished);
    $item->removeStatus(Page::statusOn);

     

    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.

  13. On 10/21/2019 at 4:51 PM, adrian said:

    By toggle off, I assume you mean "unpublish"? It's possible, but it's a real mess. However if you read through this: https://github.com/processwire/processwire-issues/issues/36 you'll be able to get it working.

    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.

  14. On 10/15/2019 at 3:07 PM, Sergio said:

    Hi Kathleen! Welcome to the forums.

    For the blogposts pages content, you need to import the database from the server. But for the assets (files folder inside templates/assets/) there's a technique to get them using hooks like Ryan shows on his post: https://processwire.com/blog/posts/pw-3.0.137/

    This is really cool - hadn't seen this tutorial before.

  15. 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.'/'
                    ));

     

  16. Unless I'm imagining it, I'm sure I've previously had the option in at least one PW installation to search/sort/filter child pages under a page's children tab. I'm working on a project that will eventually have a lot of sub-pages that the client will want to search for ease of management but I can't currently see these controls available.

    Am I simply imagining this functionality? Was it an extra module? Or does it only show up once there is enough sub-pages to paginate?... someone put me out of my misery!! ?

×
×
  • Create New...