-
Posts
695 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Jan Romero
-
Hi, welcome to ProcessWire and the forums! You have to click on “Child page example 1” first, and only then move the other page. Clicking on the new parent “opens” it, which is only really noticable in the UI by the line underneath it the background becoming slightly darker (when using Admin Theme Uikit). I agree this is way too obscure, although having to open the parent before adding a child is somewhat logical. In other systems often the parent can be coerced into opening by hovering the dragged child over it a little. That seems like a worthwhile idea here, too.
-
Hi, there is an issue about this on Github that you may want to upvote: https://github.com/processwire/processwire-issues/issues/1102. It also includes a tiny fix that has been working for me.
-
If you have a single page reference field called “author” on book pages (would probably recommend this way, even if you allow multiple authors per book): $book = $pages->get('template=book, title="The Hitchhiker’s Guide To The Galaxy"'); $author = $pages->get('template=author, title=Douglas Adams'); $book->of(false); $book->author = $author; $book->save(); If you have a multi page field called “books” on author pages: $author = $pages->get('title=Douglas Adams'); $books = $pages->find('title="The Hitchhiker’s Guide To The Galaxy"|"Life, the Universe and Everything"'); $author->of(false); foreach ($books as $book) $author->books->add($book); $author->save();
-
If you have the Apache module, I suppose the most efficient way is X-Sendfile. IIRC it would look something like this, but I’ve never done it because it’s not available on my shared hosting: header('X-Sendfile: ' . realpath($file->url);
-
module SnipWire - Snipcart integration for ProcessWire
Jan Romero replied to Gadgetto's topic in Modules/Plugins
This thread isn’t my place at all, but Gadgetto’s post you quoted tells me you need to copy the file _uikit.php from the regular site profile and somewhere at the top of your own template call include_once('./_uikit.php');. Should be a safe fix for that specific error.- 233 replies
-
- 1
-
-
- shopping cart
- snipcart
-
(and 2 more)
Tagged with:
-
Agreed. Reading the last page of this thread I was surprised this wasn’t already the case. Could be as simple as just taking a custom selector string instead of the current current single page dropdown. I suppose the idea was to have something very robust for users, since it can show up in individual page settings.
-
From cursory googling it seems jquery doesn’t support modifying the headers sent by load() specifically. This answer on SO has a somewhat messy solution that is discouraged by the jquery docs: https://stackoverflow.com/a/20067394/. Probably best to just use ajax() and select the elements yourself.
-
I think it might help to know what exactly you’re requesting. Some admin pages respond to ajax-requests with JSON and some with partial HTML. I just tested /processwire/access/users/edit/?id=40, which gives the full HTML page without ajax and a partial with ajax. As you said, PW detects ajax requests by the X-Requested-With header, so if you don’t send it or set it to something other than XMLHttpRequest, it should give you the same response you would get when navigating to the url in your browser. So, for example on the url I mentioned this works for me: $.ajax(window.location.href, { headers: {'X-Requested-With': 'justgivemethedanghtml'}, success: function (result) { console.log(result); } }) I suspect commenting out the line in ProcessWire.php didn’t help because the header is checked again in other places. The culprit is probably ProcessController.php: https://github.com/processwire/processwire/search?l=PHP&q=XMLHttpRequest. But obviously you can’t just comment that stuff out in production anyway. Just make your request pretend it isn’t ajax.
-
In general, page urls following the page tree is The ProcessWire Way™, and it’s a pretty good idea, so I’m not exactly advising you to deviate from that, but if you want to do it, it might be worth considering the other way around: /home/ /books/ /the-hobbit/ /the-very-hungry-caterpillar/ /the-luzhin-defence/ /categories/ /non-fiction/ /graphic-novels/ /really-graphic-novels/ To make your life easier you could even hook Page::path to change the urls of categories to what you want, but you don’t have that from me. (Actually, fooling around with that I just discovered a bug in a urlSegment validation regex, thanks!)
-
include _main.php only when it's not an ajax call
Jan Romero replied to froot's topic in API & Templates
uh dunno, config.php worked for me, sorry. where did you put it? -
include _main.php only when it's not an ajax call
Jan Romero replied to froot's topic in API & Templates
try putting this somewhere like config.php or something. setlocale(LC_ALL, 'de_DE.utf8'); -
I’m not certain I correctly understood the problem, but in general it will save you some headaches if you set up the page tree according to the canonical urls you want. What should be the canonical urls for specific books and specific categories? If you want a The Hobbit’s $page->url to be /books/the-hobbit and the fantasy section’s to be /books/fantasy, go with the mixing! If you want every book to have sort of a primary category, put each book under a category. Then it’ll be /books/fantasy/the-hobbit. You can still have /books/the-hobbit by using urlSegments, but you’ll obviously have to watch out for books that have the same page name as a category. And you will have to generate those links yourself somehow. I suppose you should also ask yourself if you really need the same page to be accessible by different urls?
-
Solved: Add hook to ProcessWire::init
Jan Romero replied to Studio Lambelet's topic in Module/Plugin Development
You might be interested in the new “preload module“ feature: https://github.com/processwire/processwire/commit/c4d301a40530cfa3b00ce559a14757684625a5ce But you still won’t get around what Zeka said, I guess. Can’t you just take the time in your module’s init()/__construct()? That should be the earliest opportunity for a module to do anything anyway. -
include _main.php only when it's not an ajax call
Jan Romero replied to froot's topic in API & Templates
put this in your head tag <meta http-equiv="content-type" content="text/html; charset=utf-8" /> and make sure your PHP files are UTF8. VS Code tells you in the status bar. Notepad++ has “Encoding” in the menu bar. Make sure it isn’t UTF8BOM. Is $all_events the contents of a FieldtypeTable? How much stuff is there to iterate? If you fetch a large amount of data just do discard it, it might be worthwhile to move the filtering to the database. Also if you just want all events that interesect the year somehow, you can do this foreach ($all_events as $ae) if ($ae->date_start <= $year_end && $ae->date_end >= $year_start && $ae->date_end>=$ae->date_start) $year_overview->add($ae); -
You’re not jumping in an out of namespaces in that sense (you could do that if you wanted to get really freaky). As long as you’re in the ProcessWire namespace, any function you declare belongs to that namespace. Since you’re inside the namespace anyway, you can call them without specifying ProcessWire\myFunction(), but apparently PHP’s dynamic features like call_user_func() need you to be more specific. I don’t know this per se, it’s a combination of googling and talking out of my bum bum, lol, so I’m probably getting a good amount of technicalities wrong. Here’s a link to the PHP docs about it https://www.php.net/manual/en/language.namespaces.dynamic.php.
-
PW 3.0.172 – Find faster and more efficiently
Jan Romero replied to ryan's topic in News & Announcements
@ryan Thank you for the continued effort you put into PW and the quick solution to LMD’s problem, which bit me too for a second ?! I just noticed there still seems to be an issue with the join/field selector. If used with pagination it appears to add the limit/pagesize to the total number of results, which distorts pagination. One too many pages are shown, the last of them being empty. For example, I have this selector: template=show, datum>=2019-01-01, datum<2020-01-01, has_parent=1234, sort=-datum, limit=50 With the join fields getTotal() gives me 102, without only 52 (one show per week, makes sense). Interestingly, on the second pagination page, getTotal() will say 54 (?!) and the superfluous 3rd page disappears. -
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.
-
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]);).
-
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;
-
Right, so coming back to your original post, the items you want to render are ProcessWire Pages and they’re all in one PageArray, right? Now you want to render all of them but dynamically pick a markup file based on each item’s template. You can do this similar to the way LMD suggested, by creating a file for each template and naming it accordingly. foreach ($items as $item) { $out .= $item->render($item->template->name . '_listitem.php'); } echo $out; I mean, this is basically the same as what you originally proposed, only using template files instead of functions, but the call_user_func way should work, too. If your items are only ever viewed this way, you could even just use render() without any arguments. Can you tell us more about the specific logic that goes into rendering each item?
-
Dude, at what point did I tell you to try that ? If you want to use that module, you need to familiarize yourself with it. Unfortunately there doesn’t seem to be any documentation apart from what’s in the code itself. What it does is add a method called render() to the PageArray class. Internally that calls MarkupPageArray::renderPageArray(), but you still need to write $items->render(). Now you need to figure out what arguments to pass. The information is in the code I linked. It takes an associative array of options, none of which are an actual template file like what you want to do. You could do something like this if you really wanted to: $items->render(array( 'listMarkup' => '<ul>{out}</ul>', 'itemMarkup' => "<li> <h3>{title}</h3> <p><strong>price: </strong><span>{price}</span> <p><strong>category: </strong><span>{category}</span> <p>{body}</p> </li>" )); But really, just use the foreach. Sorry for posting more confusing alternatives than anything. Do the foreach, it’s exactly what you want. You can write it in a single line if it feels cleaner. I haven’t tested any of this, I’m just writing it into the comment box.
-
Actually, I was wrong, PageArray does have a render method, but it comes through the default module MarkupPageArray. Not sure what you mean about the arrays? My code was supposed to use an arrow function. Maybe this works for you: $out .= $items->each(function($item) => return $item->render('somelayout.php')); But really, just do this foreach ($items as $item) $out .= $item->render('somelayout.php') and make sure you use $page instead of $item in somelayout.php.
-
In somelayout.php the current Page is in the $page variable! It doesn’t know $item. Otherwise your loop should work. PageArray doesn’t have a render method, although I guess you could do $items->each(fn($item) => echo $item->render('somelayout.php')); (or something like that)
-
If you’re up for it you can just create your own login form and send the input to $session->login(). That may be sufficient if you really manage everything yourself, but if you need users to do “Forgot Password”, change their passwords and all that annoying stuff, the module will probably be worth it.
-
At the risk of derailing this thread, here is the simplest way I know to get sticky pages in the admin page tree. @Violet 1. Set up a checkbox field called “sticky”. 2. Add this hook at the top of /templates/admin.php (since it’s admin specific, but ready.php will work, too): $this->addHookBefore("ProcessPageList::find", function(HookEvent $event) { $selectorString = $event->arguments('selectorString'); if ($event->arguments('page')->sortfield() === 'sort') //if manual sorting is on for the children of this page, don’t do anything. return; //just add your checkbox to the start of the selector. it will sort by this first, and additionally by the usual sort field. $event->arguments('selectorString', 'sort=-sticky, ' . $selectorString); }); 3. Check the sticky box on pages you want to see at the top. It might make sense to make the field global, but the selector won’t care even if a page doesn’t have it. Or rather, Ryan probably went to great lengths to handle such cases ?