Jump to content

Pixrael

Members
  • Posts

    394
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Pixrael

  1. Read this, it might give you an idea using JSON files:
  2. 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.
  3. Check: https://processwire.com/docs/modules/guides/comments/
  4. Off topic: htmx is in the first cohort of the GitHub Accelerator: https://github.blog/2023-04-12-github-accelerator-our-first-cohort-and-whats-next/
  5. 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
  6. 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
  7. 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');
  8. 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?
  9. An immediate and simple solution, at least for online content, can be the meta tags but for training bots: https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag https://moz.com/learn/seo/robots-meta-directives
  10. @ryan maybe this could help: https://www.phpclasses.org/package/12821-PHP-Detect-and-block-spam-bots-from-accessing-sites.html
  11. https://learn.microsoft.com/en-us/answers/questions/414790/check-if-lat-long-point-is-inside-polygons
  12. What about this? https://htmx.org/docs/#polling + the Processwire pages API to build the response
  13. Check: https://processwire.com/api/ref/wire-input/url/
  14. @ryan did you consider https://imperavi.com/ products?
  15. or.. you can use the Shopify Webhooks subscriptions too. For REST AI check here: https://shopify.dev/api/admin-rest/2022-07/resources/webhook
  16. 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.
  17. 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
  18. 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
  19. @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.
  20. 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! ?
  21. I did something similar in a project, using this library: https://github.com/Rct567/DomQuery to manipulate the content of the SVG file (it's basically XML), using file_get_contents (from file), and then modifying texts, assigning/removing css classes, hiding/removing elements, etc. In this particular case, I ended rendering the modified SVG to PNG using Imagick for the final output (delivered by AJAX). The SVG document must be prepared in advance for that. Using the proper IDs and classes. Visual styles were applied by CSS classes and not directly on elements, in order to manipulate them. Modifications were not interactive, they were captured with a form.
  22. I think in pages that need this paragraph changes you can use different fields for each region, and render the field according to the current region. Ex. body_america, body_europe, etc. You can create a function that determines to which region it belongs according to the country. If you have a license for ProFields you can use Textareas field type to handle that more easily. Pseudo code: $http = new WireHttp(); $country = $http->getJson("http://ip-api.com/json/{$session->getIP()}?fields=countryCode"); $region = getRegion($country); echo $page->body_$region; function getRegion($country) { // Set a default $output (europe) // Using an in_array, switch, etc. find the current related region to override it (america, asia, africa, etc.) return $output; }
×
×
  • Create New...