Jump to content

psy

Members
  • Posts

    738
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by psy

  1. @maddmac glad the module still works ? 

    It doesn't do anything except create new pages as per the criteria set in the module config. The new pages are simply pages - you can then query whatever you wish as normal.

    The module only has one method which adds a Hook Event after a page is saved.

    • Like 1
  2. Seems to be a problem with namespaces. Try adding namespace ProcessWire to the template:

    <?php namespace ProcessWire;
    
    include '<?php echo $config->urls->templates ?>stripe-php/init.php';
    
    //require 'vendor/autoload.php';
    use Stripe\Stripe;
    
    Stripe\Stripe::setApiKey('xxxxxxxxx');

     

  3. @millipedia

    On 10/6/2021 at 8:17 PM, millipedia said:

    These days I rarely use a framework at all.

    So with you on that! Took time to actually learn CSS, and while it's constantly changing, decided to to lose the "Sara Lee" approach - layer upon layer upon layer. Spent far too much time overriding framework defaults instead of actually doing stuff. Now I use SCSS to combine global resets, default classes, colours etc then add small per template or component stylesheets. Same for any per template JS.

    In the supply-chain world this is referred to as "just in time" vs "just in case"

    • Like 2
    • Thanks 1
  4. Apologies if this has been answered before. Great module and too many questions/anwsers TLDR...

    While I love that 'levels' is available, it applies only to <li> elements.

    I've created a multi-level CSS Only menu that's responsive for both for 'touch' and 'hover' devices. The nightmare was CSS specificity. CSS doesn't cater for 'parent' - it's in the name!

    How can I add a 'level' class to <ul> elements in the options or via a hook?

  5. @bernhard Normally I use MarkupSimpleNavigation and cache each 'page' menu with the appropriate 'active' class set. This menu is so small I decided only to cache the PageArray then output to the front end using a foreach loop and test to see if the page was 'active' and add the CSS class accordingly in the template.

    Wanted to bring it to attention in case it's a 'gotcha' for others working with custom page classes and cache. ? 

  6. Loving the custom page classes but I ran into an issue. I wanted to cache the main navigation items to save DB calls.

    Set up is:

    site/classes/HomePage.php

    site/classes/BasicPagePage.php

    and templates:

    basic-page.php

    home.php

    In _init.php:

    <?php namespace ProcessWire;
    
    // Get the nav items and save them to a cache
    /*
    This crashes with Error message:
    User Error
    Exception: Can't cache multiple page types together: HomePage, BasicPagePage (in /home/xxxxx/xxxxxx/wire/core/WireCache.php line 954)
    */
    $menuItems = $cache->get('menuItems', 3600, function() {
        $pp = wire('pages');
        $items = $pp->find("id=1|1028|1031|1029"); // Home, Gallery, Testimonials, Contact
        return $items;
    });
    bd($menuItems);
    
    // Without saving to cache works fine
    $items = $pages->find("id=1|1028|1031|1029"); // Home, Gallery, Testimonials, Contact
    bd($items);

     

  7. Having strange issues with this one as well. The field is 'body' and it has the TextformatterVideoEmbed option.

    On the same page, I have the YT URL in the page's body field. It outputs the URL.

    Below it, I have a Repeater Matrix field with the same body field and content and it outputs the video.

    Any ideas?

    Edit:

    I have found a cause but not the fix. My code is:

    <?php 
    	$featured = false;
    	if ($page->hasField('images') && $page->images->count > 0) {
            $featured = $page->images->last;
            $description = !empty($featured->description) ? $featured->description : $page->get("headline|title");
        }
    
    	// ...
    ?>
    
    
    <?php if (!empty($page->body)) : ?>
      <div class="main__body owllob">
        <?php if ($featured != false) : ?>
          <img class="main__feature-img" loading="lazy" src="<?=$featured->width(300)->webp()->url?>" alt="<?=$description?>" />
        <?php endif; ?>
    
        <?=$page->body?>
      </div>
    <?php endif; ?>

    When I include a 'featured' image and even though it renders separately to the body field, the YT URL does not convert.

    When I delete the image, it does and the video shows/plays as expected???

    Screen Shot 2021-07-08 at 24952 pm.png

    Screen Shot 2021-07-08 at 25021 pm.png

  8. Quick update...

    Finally figured out to get React/NextJS to work with a basic (minimal field types to convert to JSON) PW site. Giving self a pat on the back when I discovered Svelte ?

    Svelte felt (I'm a poet & didn't know it ?) so much more like PW - JS, HTML & CSS with 'state management' and no shadow DOM. The only problem was routing. I'd spent far too long figuring out React/NextJS routing and Svelte offered no immediate solution. The old (like 2yrs) way of routing was called Sapper. Development on Sapper has ceased with all efforts now focussed on the new way, SvelteKit which is in pre-beta (? ). Anyhoo, went with SvelteKit and got it working.

    I've only scratched the surface on what's possible with React/NextJS and Svelte. Both offer Server Side Rendering (SSR) making the site SEO friendly & fast-loading. Given a choice, I'd choose Svelte every time.

    With both React/NextJS and Svelte using @Sebi's AppApi with customisation depending on the framework, I:

    • created a home page that pulls the data from the PW home page
    • created a 'slug' page that pulls the data from the PW page url and displays it in a component based on the PW page template as returned in the page JSON, and shows the correct route in the URL from a nav menu

    In both cases, the page layout is not a PW template but a conditional component file.

    Anyone else tried Svelte with PW? Your thoughts & comments welcome

    • Like 6
    • Thanks 2
  9. I've searched, and maybe missed, the solution. I have a 'normal' images field and uploading images with a file size greater than 10Kb is fine. Any image size smaller results in the never-ending spinner and no upload.

    No min/max width/height set on image uploads in admin, ie just the defaults.

    Any ideas on how to fix?

    Using:

    PW: 3.0.175
    PHP: 7.3

    Marking it as "Resolved" rather than "Solved" as it auto-magically fixed itself. No idea whether PW, PHP, or just an internet hiccough... All good now ?

  10. On 3/19/2021 at 9:01 AM, JeevanisM said:

    Should I jump into the Node camp or not '

    @JeevanisM have no answer to that question. It's one I'm asking myself. I truly hope I don't simply to win business, especially for clients who don't need it but are being lemmings and following the hype. 

    I Googled the "benefits of REACT" and every SERP article was written by a JS developer who confused "benefits" with "features". Eg: "It manages state" is a feature, not a clearly defined benefit to the user

    • Like 3
  11. I'm really hoping the "everything needs to be node/react/js" fad/hype dies off soon. Twice today on 'important' sites (one an airline booking site), the ajax/promise/whatever failed. Was left looking a never-ending spinner. Awkward as had no idea where my flight booking went.

    Don't get me wrong, JS is useful but like most things in life, please use in moderation

    • Like 5
  12. On 3/9/2021 at 4:41 PM, csaggo.com said:

    confirmed it myself

    Yep, everything I had working with AppApi and REACT/NextJS broke with the PW 3.0.173 upgrade. Downgrading is a short-term option but limits future PW upgrade benefits

    • Thanks 1
  13. @Sebi Thanks for the quick response. I'd already gone past that point both in PW and Postman so the connection is good.

    I'd even written my own method in Examples to get a page by ID. Maybe not as sophisticated as yours but it too worked:

    <?php namespace ProcessWire;
    
    Class Example {
      
      	public static function test () {
    		return ['test successful'];
    	}
    
      
          public static function getPageById($data) {
            $data = AppApiHelper::checkAndSanitizeRequiredParameters($data, ['id|int']);
    
            $p = wire('pages')->get("id=$data->id");
            if(!$p->id) throw new \Exception('Page not found', 404);
    
            $response = new \StdClass();
    
            // Hardcode any data you need that does not have an inputfield field in the admin
            $response->id = $p->id;
            $response->name = $p->name;
            $response->path = $p->path;
    
            // This retrieves all the admin input fields. Does not (yet) get page images or files, just single entry data
            $fields = $p->getFields();
            foreach ($fields as $fld) {
                $fldName = $fld->name;
                $response->$fldName = $p->$fld;
            }
    
            return $response;
        }
    }

    This enabled me to get the page data into the NextJS client and embed in the 'template/component' as variables from any existing PW page.

    My next exercise was to delve into the NextJS router so that I could retrieve pages via their path and those paths would appear in the URL. Couldn't work it out in my own PW code (no surprises there!). It was then I installed your Twack module and used the Twack routes & TwackAccess.class.php at which point I ran into the issues mentioned above.

    I'm sure it's my lack of knowledge of REACT/NextJS rather than your code... Doesn't help when their doco doesn't match up with their examples in gitHub.

    Even so, it would great to use your TwackAccess classes rather than reinventing the wheel.

     

     

     

  14. Excited to be learning REACT/NextJS. It's so 'on-trend'. 

    I can double my hourly rate, take 3x as long to deliver a website with 2/3 of the Google Lighthouse results and who doesn't love the spinner while the component content loads? 

    Doing a well optimised PW site with minimal JS, fast page loads, accessibility, SEO and more built in is so old hat.

    And even better, with JS frontends, the code maintenance goes on and on. No end to revenue possibilities.

    FML

    • Like 7
    • Haha 9
  15. I've read the doco, installed the module & Twack and no matter what I try when retrieving a page, all I get back is a successful Promise or worse, an error message about invalid json. Using React/Nextjs and the page is published, viewable & using the basic-page template. The authorisation is single JWT and the client JS code is:

    export async function PWPageByUrl(path)  {
      // url is correct and returns a result, just not the one I was expecing
        const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/page/${path}`, {
                headers: {
                    'x-api-key': process.env.NEXT_PUBLIC_API_KEY,
                    'authorization': process.env.NEXT_PUBLIC_TOKEN
                }
            }
        )
        const data = await res.json()
        if (!data) {
            return {
                notFound: true,
            }
        }
        return {
            props: {
                data
            }, // will be passed to the page component as props
        }
    }

    On the PW server side as per doco with routes modified for v1, I have:

    Spoiler
    
    <?php
    namespace ProcessWire;
    
    require_once wire('config')->paths->AppApi . "vendor/autoload.php";
    require_once wire('config')->paths->AppApi . "classes/AppApiHelper.php";
    
    require_once __DIR__ . '/TwackAccess.class.php';
    
    $routes = [
    
        'v1' => [
            'page' => [
                ['OPTIONS', '{id:\d+}', ['GET', 'POST', 'UPDATE', 'DELETE']],
                ['OPTIONS', '{path:.+}', ['GET', 'POST', 'UPDATE', 'DELETE']],
                ['OPTIONS', '', ['GET', 'POST', 'UPDATE', 'DELETE']],
    
                ['GET', '{id:\d+}', TwackAccess::class, 'pageIDRequest'],
                ['GET', '{path:.+}', TwackAccess::class, 'pagePathRequest'],
                ['GET', '', TwackAccess::class, 'dashboardRequest'],
    
                ['POST', '{id:\d+}', TwackAccess::class, 'pageIDRequest'],
                ['POST', '{path:.+}', TwackAccess::class, 'pagePathRequest'],
                ['POST', '', TwackAccess::class, 'dashboardRequest'],
    
                ['UPDATE', '{id:\d+}', TwackAccess::class, 'pageIDRequest'],
                ['UPDATE', '{path:.+}', TwackAccess::class, 'pagePathRequest'],
                ['UPDATE', '', TwackAccess::class, 'dashboardRequest'],
    
                ['DELETE', '{id:\d+}', TwackAccess::class, 'pageIDRequest'],
                ['DELETE', '{path:.+}', TwackAccess::class, 'pagePathRequest'],
                ['DELETE', '', TwackAccess::class, 'dashboardRequest'],
            ],
            'file' => [
                ['OPTIONS', '{id:\d+}', ['GET']],
                ['OPTIONS', '{path:.+}', ['GET']],
                ['OPTIONS', '', ['GET']],
    
                ['GET', '{id:\d+}', TwackAccess::class, 'pageIDFileRequest'],
                ['GET', '{path:.+}', TwackAccess::class, 'pagePathFileRequest'],
                ['GET', '', TwackAccess::class, 'dashboardFileRequest']
            ]
        ]
    ];

    and the TwackAccess class copy/pasted from the documentation, eg for pagePathRequest:

    Spoiler
    
    
      <?php
    	/**
         * General function for page-outputs:
         */
        protected static function pageRequest(Page $page) {
            // Exit if Twack is not installed
            if (!wire('modules')->isInstalled('Twack')) {
                throw new InternalServererrorException('Twack module not found.');
            }
    
            // This commands Twack to output a data-array instead of HTML:
            wire('twack')->enableAjaxResponse();
    
            // If the page has no template, is not accessable or is blocked (i.e. via hook),
            // we throw a ForbiddenException
            if (!$page->viewable()) {
                throw new ForbiddenException();
            }
    
            $ajaxOutput   = $page->render();
    
            // $ajaxOutput will contain JSON-code, so we have to decode it to prevent it is encoded twice:
            $results      = json_decode($ajaxOutput, true);
    
            // Now, $results is a clean PHP-array with the information generated by Twack-components:
            return $results;
        }

     

     

    I'm obviously missing something. Help to get it working as expected much appreciated.

    Thanks

     

×
×
  • Create New...