Leaderboard
Popular Content
Showing content with the highest reputation on 02/17/2021 in all areas
-
This is what I wrote ryan lately: And that was his response: Now the topic came up here: https://processwire.com/talk/topic/20668-page-hit-counter-–-simple-page-view-tracking/?do=findComment&comment=211318 As this is getting offtopic in the pagehitcounter thread I suggest to continue discussion here @adrian @David Karich What do you think? Have you ever had the need for a custom endpoint in your projects? How did you solve it? Which issues did you have? Let's collect some examples so that ryan can see "more specifically what we are talking about" ?8 points
-
Instead of ProcessMention, you may want to look at its successor CKInlineComplete. It's got a bit of boilerplate so you can easily extend it with your own InlineCompleteAction. Creating an action module that searches the name or title of answer pages and returns the anser's HTML from a field there should be straight forward. I guess it would be possible to extend the functionality to plain textareas as well, though the code in plugin.js makes use of CKE's range api a lot and positioning relies on its iframe, thus it would mean a bit of refactoring work.5 points
-
The last 5 projects all needed some kind of API endpoint. Over time, I've settled for a custom "api" page under home. In two projects, this is a very simple piece of code with a switch statement, in others it looks for individual templates under templates/api. I'm not completely happy with any of them, though, and I've often wished for something akin to hooks with enough boilerplate to avoid repetitive code. I do concur that Laravel has some very nice and expressive features. I could picture a WireApi singleton class with which modules could register, and a fixed "api" page that is by default not much more than <?php namespace ProcessWire; wire('api')->handleRequest(); WireApi may or may not route to matching PHP files under templates/api by default. Autload modules could register their routes in their init() method. Just a rough example with one or two Laravel niceties stirred into the usual PW awesomeness to get a nice declarative approach to api route definitions: <?php namespace ProcessWire; class ApiExampleHandler extends ApiRoute { public static function getModuleInfo() { return [...]; } public function init() { parent::init(); # hand GET requests to /api/users/USERID/profiledata off to our getUsrProfileData method # and pass the value in place of USERID as the first parameter $user to the method. # Use $sanitizer->intUnsigned on $user to make sure it is a valid page id. $this->api->get('/users/{user}/profiledata', $this, 'getUserProfileData')->whereSanitized('user', 'intUnsigned'); } public function getUserProfileData($user) { $u = $this->users->get($user) ?: $this->api->notFound(); $p = $u->profilepage ?: $this->api->notFound(); # Set Content-Type header, set json_encode return value and output it $this->api->jsonResponse([ 'nickname' => $p->nick, 'hobbies' => $p->hobbies, 'membersince' => $p->joindate ]); } } Something along those lines could go a long way to making endpoint implementation easier. I don't know how often I've checked for isAjax et al, called json_decode and json_encode, checked the request method, sanitized and compared urlSegement1 and urlSegment2 and urlSegment3 (and sometimes even urlSegement4) in nested conditionals... For quick and dirty solutions, api route registration could go into api.php before handleRequest() is called, or even into site/ready.php. With a bit of creative magic, a nice PWish equivalent to Laravel's model binding should also be in the realm of possible things.4 points
-
I've had a chat with ryan about exactly that topic lately! It seems he liked the idea, so I'll add your conversation to our chat and report back what he says ?3 points
-
You’re in ProcessWire’s namespace, so if you paste the code you linked, those functions will actually be ProcessWire\exclaim() and ProcessWire\ask(). You can call them like this: printFormatted("Hello world", 'Processwire\exclaim'); printFormatted("Hello world", __NAMESPACE__.'\ask'); Or alternatively, you can add the namespace in printFormatted: function printFormatted($str, $format) { // Calling the $format callback function echo (__NAMESPACE__ . '\\' . $format)($str); } Or you could declare exclaim() and ask() differently. For example by putting them in a class or in an include file with a different/global namespace.1 point
-
Excellent question, because the documentation on it is a little stupid. The information is here: https://processwire.com/api/ref/page-render/render-page/. Although if you really want to see what’s going on, you can look at the code directly: https://github.com/processwire/processwire/blob/master/wire/modules/PageRender.module#L399. One would expect this to show up in the documentation for the Page class, but there isn’t even a link… The reason it’s a little convoluted is that the render method is added by a Module as a Hook, so I guess it doesn’t technically belong to the Page class. Maybe it’s not really supposed to be used that way. You wouldn’t have all that trouble with append files and cache using LMD’s method. However, you would need to pass your $item to it somehow (for example $files->render('yourfile.php', ['item' => $item]);).1 point
-
Good point. The render method will render the page according to all the usual settings, so for this use case you’ll need to disable any prepend/append files. If you have template caching enabled, you need to turn that off, too. You can call render with options like so: foreach ($items as $item) { $out .= $item->render($item->template->name . '_listitem.php', ['prependFile' => null, 'appendFile' => null, 'allowCache' => false]); } echo $out;1 point
-
1 point
-
I have several almost the same cases. We are running several news sites where every news item page have an image and this image at least have two variations, one for the intro (390x240) and second for full article view, so I would like to set admin thumbs to 390x240 and with specific quality settings, so we could reuse this variation on frontend. In this scenario with the current amount of pages, we can save up to ~7GB of storage space. @gebeer Could you please open an issue in feature-requests repo?1 point
-
Same here. This is probably windows specific problem - at least in our company it is.1 point
-
Yes, I understand. Unfortunately, this case cannot be mapped with the module, because the whole core concept is based on triggering a 404 via a non-existent endpoint and hooking in before it. I wanted to keep it simple and not have to install an additional page as API endpoint and a template for it. ?1 point
-
@ryan Since upgrade to 3.0.172, I have this notification alert : And if use "Publish" button to publish a page I have this notification alert : But if I uncheck "Unpublish" or if I publish from page list, the page is published. Any idea ? How can I look for something to resolve it ?1 point
-
Vielen Dank, Bernhard! Now I've put that into my ready.php and it works great. Just one thing occurred that is Umlauts are html-encoded. I.e. when having this URL: https://domain.com/processwire/tools/ourmodule?Param1=Fünf after the login it is transformed to: https://domain.com/processwire/tools/ourmodule?Param1=Fünf which essentially looses part of the value because & of course is the URL param separator. I've tracked this down into the ProcessLogin module and it seems that this line should NOT be: if(!is_int($value)) $value = $this->wire('sanitizer')->entities($value); but rather: if(!is_int($value)) $value = rawurlencode($value); because the URL string is manually built by concatenation. After fixing this in the Core our links now work great. Thanks again for your help, Bernhard. What do we do about this bug (?) in the Core module?1 point
-
I'll just leave this here: How to set up Twig as a flexible view layer for ProcessWire and/or Create flexible content modules using Repeater Matrix fields The feature you're looking for is template inheritance – the ability to have a base template which is extended by child templates. The child templates can then override any block they want to. If you go down the path of wireRenderFile or MarkupRegions you'll always notice you're fundamentally lacking the ability to overwrite blocks in a parent template. With pure PHP templates, you'll always end up with a system that either needs to import a bunch of partials in every new template, just for the ability to leave out or change some of them for one particular template. Or your base template will need to be aware of every possible permutation and arrangement of partials and mixins in all your templates, resulting in messy and unmaintainable code which grows linearly with every template you add. Using a template system with template inheritance solves that for you and makes your template system infinitely scalable (besides other benefits like autoescaping and better readability).1 point
-
There is also additional options for field rendering https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/ https://processwire.com/blog/posts/processwire-3.0.7-expands-field-rendering-page-path-history-and-more/#field-rendering-with-template-files1 point
-
Without needing to buy a Pro module (although they are excellent!), there is indeed a ProcessWire way for this. You can use $files->render()/wireRenderFile() to achieve what you want: https://processwire.com/api/ref/wire-file-tools/render/ https://processwire.com/api/ref/functions/wire-render-file/ The advantage of using this over your own functions is that it will automatically keep access to all of PW's API variables (no need to pass them in). Here is a simple example based on your use-case description: /** * In your generic template file. * Note: it assumes there is a directory under 'templates' called 'layouts' (it could be called anything). * Just create your layouts in the 'layouts' dir and name them the same as the '$item->template' names you are using. */ // Get the content of the specified layout into a variable. // This example looks for '/site/templates/layouts/name-of-template.php' (the .php extension is assumed) $pageContent = $file->render('layouts/' . $item->template); // Just echo it out wherever you need it. echo $pageContent; Read the docs on it, there is more you can do with this method/function, including passing custom variables, and some other options to make it more flexible. There is also a $files->include() method which is the same except it directly echos out the content instead of returning it to a variable.1 point
-
Ok, I get it now, but it is pretty confusingly worded - either that, or I am just a bit slow ? Anyway, it's easy enough to add, but do you think the icon should be displayed for all users, or just superusers? Also, which icon - the issue is that the key and lock icons are already used in the page tree for other indicators. The other question I have is whether to use the ProcessPageListRender::getPageLabel hook and add the icon as a "PageListStatusIcon" like the lock, exclamation icons are added by the core (at the end of the title in grey), or using the Page::getIcon hook which adds to the front of the page title and the icon is pink. I think the "PageListStatusIcon" option is more correct and looks nicer, but it means that it will be broken on sites that use that ProcessPageListRender::getPageLabel hook to modify the page titles - something I do on a few sites. Of course the other option would be if this wasn't included as part of the module, but rather those who want it can add it themselves with one of those hooks like this: $this->wire()->addHookAfter('ProcessPageListRender::getPageLabel', function($event) { $p = $event->arguments[0]; if($p->protected) { $event->return = $p->title . "<i class='PageListStatusIcon fa fa-fw fa-key'></i>"; } }); OR $this->wire()->addHookAfter('Page::getIcon', function(HookEvent $event) { $page = $event->object; if($page->protected) { $event->return = 'key'; } });1 point