-
Posts
396 -
Joined
-
Last visited
-
Days Won
3
Everything posted by Pixrael
-
tursodatabase/turso-client-php: Turso - libSQL client libraries and utilities for PHP (github.com)
-
How to track all called $page->* properties (fields) ?
Pixrael replied to ukyo's topic in General Support
Read this, it might give you an idea using JSON files: -
The method proposed by @ryan here isn't bad, but it doesn't allow nested fragments. In the case of complex views (web apps, calculators, etc.) with different user actions where several calls are needed for different sections of the page, and we (almost always) need fragments that are inside larger fragments. I'm currently working on my first Processwire module, which can help to use these fragment-based systems. I've been implementing several methods, and only one of them prevents the entire content of the template file from being rendered. It works but requires some conditions, ex. in the case of a single template file with markup regions, you should organize your code to put the creation of all content variables at the beginning of the file and completely separate from the output HTML markup. The idea is that during rendering it collects the requested fragments from the template file and saves them to a temporary PHP file, then includes it in the template file at the point before full HTML output occurs, and then stop the rendering the template file. It's basically like a dynamic partial. The advantage is that you don't need to split the template files into several parts (nested fragments will be a nightmare) and avoid to put a lot of conditionals in the code. It also helps that if you have a new type of request, you only need to declare in the request which parts of the page to fetch. @elabx if you're interested, I have a Hook version of this that I used during testing. Note: It would be great if the Render method, in addition to the current template file, would also accept an HTML string. This avoid the use of temporal files.
-
GREAT!!!!! ?
-
Check: https://processwire.com/docs/modules/guides/comments/
-
in fact I have a method in the custom page class for that: if (HTMX Blah Blah) $page->renderFragment("todo", [array], "200 OK"); function renderFragment($filename, $bag, $code) { header("HTTP/1.1 $code"); wire("files")->include("services/partials/{$filename}.php", array('view' => $bag)); exit(); } .. but I love to use Markup regions in my projects, and I hate using tens of partial files, that's the reason for the proposal. Get the "partials" from the same template file that I render in the page request. It's a simple helper in tune with Processwire Markup Regions
-
I get it, in PW it can be done too with $files->render() ..now do the example without partials ? I mean when a page has many moving parts, you have to dissection too much the "view" in files, and it becomes complex (not impossible) to handle... I want to make clear my first post says that it can be done now, in fact I have done it... but it would be much more productive and simple something like what I propose .. but it's only an idea based on my opinion
-
All that you describe is very good for simple examples like the ones you put here, but when it's a much more complex page, or a web application, with several different elements that you want to update, it starts to become complex. You need to start dissecting the template file into small partial files (or even worse build the markup with PHP variables) to be able to render different types of requests to the same template, and it's a mess! ex. complex forms with dependencies between the fields, updating graphs or tables, panels with details of the selected element, couple of counters in different location in the page, etc. The idea is to be able to use the same original template file that initially rendered the page, and that can be used with Markup Regions if you wish. Response with a whole page as @bernhard proposes (although it's already cached, you need to update it with the new query) and send the complete page each time you need to update something, ex. only one <select> element, small text or a counter, these kind of pages regularly weigh MBs ..It's very unreasonable ..is better to reload the page. The ideal is to send the exact piece of html that you need to update on your initial page render. @bernhard Latte already support this kind of rendering. Using the 3rd parameter to only render 1 block from the template $Latte_Engine->render('path/to/template.latte', [ 'foo' => 'bar' ], 'content');
-
I have been using HTMX recently and it really is a very good option. Of course all of its functionality can be achieved using the Processwire API, and including partial files in the template file. But it would be wonderful to have some kind of facilities in our framework. Maybe with a new method in the PageRender class, that allows to select specific elements of the template file markup. The following is a simple idea based on the Markup Regions syntax: <pw-region id="content"> <h1><?= $page->title ?> <?= $page->summary ?> <h2>Contact Details</h2> <div id="contact_info" pw-fragment> <p><strong>$page->contact_name</strong></p> <p>$page->contact_address</p> </div> <h2>Social Channels</h2> <div id="total_likes" hx-swap-oob="true" pw-fragment> <a href="https://www.facebook.com/">$page->likes</a> </div> <p>Please, Call Us!</p> </pw-region> Since I'm not a programmer and I don't really understand very well how PW works inside, perhaps one of the following options can work to execute the rendering of the fragments (It can use the Find method that Markup Regions has for HTML tags) $output = $page->render("#contact_info#total_likes"); $output = $page->render("basic-page.php#contact_info,total_likes"); $output = $page->render("fragment=contact_info|total_likes"); $output = $page->fragment("contact_info|total_likes")->render(); $output = $page->render()->fragment("contact_info|total_likes"); $output = $page->renderFragment(["contact_info","total_likes"]); wireFragment() Of course this method does not use the append file of the "_main.php", perhaps doing a: $this->halt(); Laravel Blade has this already implemented for precisely the same purpose. Check this video: https://youtu.be/3dPUsXsDZsA https://htmx.org/essays/template-fragments/ @ryan what do you think about this? Everyone, would this be a good idea? ..or something similar?
-
@ryan maybe this could help: https://www.phpclasses.org/package/12821-PHP-Detect-and-block-spam-bots-from-accessing-sites.html
-
https://learn.microsoft.com/en-us/answers/questions/414790/check-if-lat-long-point-is-inside-polygons
-
Need some help with long polling configuration
Pixrael replied to Flashmaster82's topic in General Support
What about this? https://htmx.org/docs/#polling + the Processwire pages API to build the response -
-
How to redirect the user back to desired URL after login page?
Pixrael replied to tires's topic in General Support
Check: https://processwire.com/api/ref/wire-input/url/ -
New post – Reconsidering the CKEditor 4 to 5 upgrade
Pixrael replied to ryan's topic in News & Announcements
@ryan did you consider https://imperavi.com/ products? -
or.. you can use the Shopify Webhooks subscriptions too. For REST AI check here: https://shopify.dev/api/admin-rest/2022-07/resources/webhook
-
If you plan to export and import pages at some point, ex. development to production. I recommend that you never use page IDs in selectors, or in other places where they acts as hard data. Because (during the import) the ID value of the source can change depending on the availability of the number in the destination, and that can destroy your code logic.
-
Also you can check this https://processwire.com/modules/process-wire-bootstrap4/ and look at the _func.php file, this was for BS4 but maybe you can adapt it easily to your BS version
-
try to use $page->viewable() instead of asking for the user role.. and report back to us Note: if you want the logged user to only be able to check his own profile, you must add this check also, comparing the ID from the urlSegment with the ID of the current user
-
@ryan a possible solution for future enhancements to MarkupRegions is that only comments starting with <!--# are the ones that will be removed in the process and the original html comments will be kept. @gebeer you can try to make that modification in your copy of the code.
-
allow access to single php files in templates folder for ajax processing
Pixrael replied to ttbb's topic in General Support
You can also create a new template (ex. api) with just the title field. Create the template file (ex. api.php) and publish a page on your site without access restriction (ex. domain.com/api) and that's it. In your template file (which is your entry point) you can use: $input->post(), $input->get() or urlSegments to get the request data, and then you can include files, or execute functions or whatever you want. Finally you print everything in JSON format, or in html format if you want to use htmx. Piece a cake! ?