Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/18/2025 in Posts

  1. Padloper is dead! Long live Padloper! It is official! Padloper is now ProcessWire Commerce. ProcessWire Commerce is a free, open-source fully featured e-commerce module (plugin) for building and managing fully function online shops (stores) in ProcessWire. It is flexible, extensible, highly customisable, scalable, robust, multilingual by design and battle tested. Pro Support ProcessWire Commerce is designed to be easy to develop with and to use. For some, you might need extra reassurance that professional help will be available if you need it. Or, you might have a question about how to perform a certain thing or wish to support the project to ensure that any issues are dealt with quickly. Or you might want to sponsor a particular feature. If this is you, Pro Support and custom development can be purchased from my website. Community Support These forums. Donations If you value my work or my work helps support your work or you just want to say thanks, please consider donating. Thanks! Requests Modalities are still being worked out. Please note: I'll add features at my own pace; if and when I can (reasons for this discussed elsewhere in the forums). I'll focus on security, PRs and maintaining the project and major bug fixes. I hope community will contribute. Sponsored (pay for a feature) features: This can be by individuals or community driven. Please contact me for availability. Known Bugs ProcessWire Commerce Admin GUI is broken in the new admin theme, i.e., ProcessWire 3.0.248 (or newer). Save + Exit and similar broken on some pages at some recent ProcessWire version. Manually order creation broken (backend). Please file bug reports in the repo here - https://github.com/kongondo/ProcessWireCommerce/issues. Contributing This is a community project. All contributions are welcome! We are still working out how the 'how'. Documentation Please see this thread. Other Important Stuff Migrating from Padloper. Community help request. Tech Stack ProcessWire (PHP). Vanilla JS htmx Alpine JS Tailwind CSS MySQL Download Here you go!
    5 points
  2. I use the Docker image from solidnerd (https://github.com/solidnerd/docker-bookstack) witch Docker Compose. Where I stumped was, that you have to set some settings as environment variable not in a .env-file, but give it docker on runtime. My hole setup is on a v-server with portainer and the nginx proxy manager. Bookstack (+MySQL) and NPM share the same network, what makes the configuration on the NPM side easier. Setup as a "stack": The config with the setup of the environments variables: Created containers from the stacks above: The in before created network "proxyable": Hope the little inside example help. Updating is super easy. You update the image and then let the container rebuild on the latest.
    2 points
  3. ProcessWire Commerce will be here later today. As mentioned in earlier discussions, my hope is that this will very much become a community project. ProcessWire Commerce is a mature project that powers hundreds of shops, big and small. There still some work needed to make it better. This is where you can chime in, to the extent you can. Please note: I don't have it all figured out yet. With your help, we can figure it out together, including the contribution process. Below are the things that currently need to be worked on. Documentation: Frontend documentation - for frontend developers: End-to-end how to work with ProcessWire Commerce in the frontend to build a shop. Backend documentation - for shop editors. How to use the GUI to configure, build, run and manage a shop. API documentation - for documenting how ProcessWire Commerce is built, developing for it and contributing. Still considering if/how to how to host documentation. Suggestions welcome. Fix Bugs Identify, report and suggest bug fixes. Please file bug reports in the repo here - https://github.com/kongondo/ProcessWireCommerce/issues. Fork the project, fix bugs and submit PRs. Tutorials Help write ProcessWire Commerce tutorials for different audiences. Help create demos. Ecosystem Help grow the project. Star it on GitHub. Create add-ons. Build migration tools. Create a logo for ProcessWire Commerce. Help write unit tests (???) Site Profiles Help develop an official, multi-lingual, modern site profile/theme to be used to showcase ProcessWire Commerce. Contribute site profiles or themes.
    1 point
  4. If I have a Datetime field on my page and the field is not empty then the getUnformatted method returns the integer for the Unix timestamp (as expected), but if my field is empty then getUnformatted returns an empty string. I would have expected it to return the integer 0 as that's the raw value for an uninitialised timestamp. I think this is unintuitive, and inconsistent with the way the system datetime fields work. With two non-empty dates (using the current timestamp as an example), you get compatible results: $page->getUnformatted('my_date') === 1750221096; $page->getUnformatted('published') === 1750221096; $page->getUnformatted('my_date|published') === 1750221096; With two empty dates (e.g. if the page hadn't been published yet) you get incompatible results: $page->getUnformatted('my_date') === ''; $page->getUnformatted('published') === 0; $page->getUnformatted('my_date|published') === null; I think the getUnformatted method should return an integer 0 for an uninitialised date. Does that sound reasonable, or is there a particular need for it returning a string instead? I can see that returning a string could be handy if you want to distinguish between an empty date and a date that's actually set to 1 January 1970 at 00:00. If that's the logic to it then I'd submit a pull request for the documentation to be changed so that it's clear what getUnformatted returns with Datetime fields.
    1 point
  5. On the "Settings specific to Page Auto Complete", can you add the field "notes", to the search fields? Also I would try on selector string of the Selectable page soptions removing the "title|notes%=query", since this would not seem what you want? Otherwise only pages with the word "query" on the notes field would be selectable. template=paclage, sort=title
    1 point
  6. I can confirm what szabesz is saying. I using it on a private project with near 100 members. It is comparing with other documentation tool for cooperative writing, easy and also for not techies usable. One of the best parts is... you can export pages or books (structure collection of pages) in pdf and co. And that also via an API. Meaning, I can serve some handbooks via a Website Frontend as PDF, and it is the actual updateded document on that topic possible. (Maybe in the case here, not so useful, but as an example...)
    1 point
  7. First of all, thank you for all your heroic efforts! And I am not exaggerating. Please consider https://www.bookstackapp.com/ Free, open source, and contributors do not have to set up anything. I've used it, it's great, stable, and its developer is actively working on it, improving it regularly.
    1 point
  8. @AAD Web Team, the issue of if PW is not doing something it should isn't something we can resolve in the forum as it's a question for Ryan and he doesn't routinely read all topics. To get an answer on that you'll need to raise an issue in the Issues or Requests repos, depending on if you think it's a bug or rather a feature you would like to have. But to solve your immediate problem you can use the hookable method I mentioned. You use whatever custom code you have to get a username back from the supplied email address and then use that with the supplied password to attempt a login. $wire->addHookBefore('ProcessLogin::loginFailed', function(HookEvent $event) { $session = $event->wire()->session; $username_or_email = $event->arguments(0); // Maybe return early if not dealing with an email address if(strpos($username_or_email, '@') === false) return; // Dummy function indicating where you get the username from an email address using your custom code $username = getUsernameFromEmail($username_or_email); $password = $event->wire()->input->post('login_pass'); $u = $session->login($username, $password); if($u) { // Login was successful for the given username and password // Redirect to admin $session->redirect($event->wire()->config->urls->admin); } });
    1 point
  9. ProcessWire Commerce is a free, open-source fully featured e-commerce module (plugin) for building and managing fully functional online shops (stores) in ProcessWire. It is flexible, extensible, highly customisable, scalable, robust, multilingual by design and battle tested. The current features are: Core Features Product Management: Create and manage unlimited product listings with options for unlimited variations, pricing, and descriptions. Support for 4 product types: Physical with shipping, physical without shipping, digital and services/events. Optionally track stock. Order Management: Process and manage orders, handle refunds, print invoices and communicate with customers. Frontend order placement and backend manual order creation. Shipping Options: Configure shipping methods, rates, handling and zones based on location and product type. Rates can be tiered and based on weight, price, quantity or flat. Support for 'rest of the world' shipping. Tax Management: Calculate and apply taxes automatically based on location and product type. Prices can include/exclude taxes. Tax overrides can be added to product categories (collections) and/or shipping. Analytics & Reporting: Gain insights into sales, customer behavior, and product performance. Payment Gateways: Integrate with numerous payment processors to securely accept online payments. Invoice, Stripe and PayPal included by default. Easily add your preferred gateway. Optional Features Inventory Management: Track stock levels, manage back-orders, and set up low stock notifications. Product Categories (collections). Product Tags. Product Attributes (for product variants, e.g. colour, size, etc). Product Types: 'Phones', 'Books', 'Shirts' and so on. Product Brands: Create and manage shop product brands/vendors/manufacturers. Product Properties: Further describe products based on various properties such as 'Colour', 'Grade', 'Weight', etc. Product Dimensions: For instance, 'Centimetres', 'Kilograms', 'Litres', etc. For use with Product Properties. Downloads; Digital products or files that accompany a product such as 'tickets', 'manuals', and so on. Discounts: Redeemed by customers or applied automatically at checkout. Support for four types: Fixed, Percentage, Shipping and Buy X get Y (last one is WIP). Discounts can be applied to whole order, parts of it, to select customers or countries. Customer Management: Create and manage unlimited customers. Can be created at checkout (using the API and/or hooks) or manually in the backend. Email customers directly from admin. Customers can have multiple addresses. Customer Groups: Create and manage unlimited customer groups Add customers to as many customer groups as needed. Customer groups can be targeted for marketing, promotions, etc. Legal Pages: Create and manage legal pages such as 'Shipping Policy', etc. Gift Cards: WIP. Move some pages from /admin/shop/ to a parent in the home tree. With your help, we can add more features 😀!
    1 point
  10. This week I’ve bumped the dev branch version number to 3.0.249. This includes a little under 20 commits with various small updates, also including several to the new AdminThemeUikit default theme. This will likely continue for a couple more minor versions on the dev branch as we continue to optimize and improve it. See dev branch commit log for more details. I’m currently developing a portal application in ProcessWire for a client, and also working to finish up the ProcessWire.com website with the new design. We’re getting very close to having it technically ready, leaving just some writing for the homepage and features sections of the site. So the new site could be online in as soon as the end of the month. Stay tuned! Thanks for reading and have a great weekend!
    1 point
  11. Page classes are an outstanding feature of ProcessWire and probably ranks among my favorites overall (and that's really saying something with ProcessWire). I don't remember how I lived without them, well I do, but I don't like to think about it. I wrote a response to a question asking how ProcessWire can help transition from procedural code to OOP and in the process (pardon the pun) of answering, I realized how much I've come to use, if not outright rely on, page classes in every project. I wanted to compile a few more thoughts and examples here because there may be devs who are finding this feature for the first time, and besides, why not go down the rabbit hole? Page classes have been around since ProcessWire 3.0.152 and if you're not familiar this will all make a lot more sense if you do a quick read of the feature announcement by Ryan here because this post assumes familiarity. We're also going to pick up the pace between the examples below compared to my comment in the link above. Here are a few goals that I have that page classes put solutions for within reach. You may have some of your own and I'd love to hear about those as well. Keep templates clean by restricting logic to flow operations- if statements and loops. Work with data in context, accessing data and fields closer to their source. Create "universal" methods available in every template, but also have scoped methods per-template Increase the scalability of a project, growth with limited increases in complexity. Stay DRY Embrace and extend the power of OOP in ProcessWire's DNA This seems like quite a list for one feature to handle, but rest assured, this is an example of how much power comes with using page classes. I'll continue and build on the blog example from my linked response above, and you can "follow along" with the Blog module since the templates mentioned are present out of the box. Some of the examples below are taken from production code, but please excuse any errors that I may have introduced by accident and I'm happy to update this post with corrections. Some of these things can be done other ways but they're just to illustrate, replace with your ideas and think of times that this would be useful. First up, what are some features and behaviors that everyone needs on every project? What are some universal methods that would be great to have everywhere? Let's start out by creating a "base" page class called DefaultPage. Going forward, page classes will extend this class instead of Page and benefit from having access to universal methods and properties. EDIT: I initially wrote this using BasePage rather than DefaultPage for this class name as described by the custom page class writeup by Ryan in the article above. I've changed this to now use the correct DefaultPage class name. <?php namespace ProcessWire; // /site/classes/DefaultPage.php class DefaultPage extends Page { /** * Returns all top level pages for the main navigation. */ public function navigationPages(): PageArray { $pages = wire('pages'); $selector = 'parent=1'; $excludedIds = $pages->get('template=website_settings') ->nav_main_excluded_pages ->explode('id'); // Check for excluded pages from nav defined in the "Website Settings" page count($excludedIds) && $selector .= ',id!=' . implode('|', $excludedIds); $homePage = $pages->get('id=1'); $topLevelPages = $pages->find($selector); $topLevelPages->prepend($homePage); return $topLevelPages; } } All your base page are belong to us. Right off the bat we've managed to pull complex logic usually in templates and kept our markup clean. This isn't for DRY, it's to store logic out of templates. This simple example only illustrates working with a top level page nav. We can start to appreciate the simplicity when considering how much more the navigation may call for in the future. A navigationChildren method that also accounts for excluded pages is a prime example. In our markup: <!-- /site/templates/components/site_nav.php --> <nav> <ul> <?php foreach ($page->navigationPages() as $navPage): ?> <li> <a href="<?= $navPage->url; ?>"><?= $navPage->title; ?></a> </li> <?php endforeach ?> </ul> </nav> Next up, our settings page has newsletter signup fields where users can copy/paste form embed code from Mailchimp. Our website has a "settings" page where global values and fields can be edited and maintained There are multiple textarea fields on the settings page that can each contain a different mailchimp embed code There is an embed select field that can be added to templates. The values are textarea field names so an embed can be chosen by the user. An embed select field has been added to the settings page which allows for choosing a default embed code if one isn't selected when editing a page Embedded forms should be available anywhere on any template <?php namespace ProcessWire; // /site/classes/DefaultPage.php class DefaultPage extends Page { // ...Other DefaultPage methods /** * Renders either a selected form embed, fallback to default selected form */ public function renderEmailSignup(): ?string { $settingsPage = wire('pages')->get('website_settings'); $embedField = $this->signup_embed_select ?: $settingsPage->default_email_embed; return $settingsPage->$embedField; } } Excellent. We've got some solid logic that otherwise wouldn't have a great home to live in without page classes. We can also modify this one method if there are additional options or complexity added to the admin pages in the future. Wherever we use renderEmailSignup, the return value will be either the selected or default form embed code. Let's create a folder called "components" in our templates directory that will hold standalone reusable markup we can use wherever needed, here's our newsletter signup component: <!-- /site/templates/components/newsletter_signup.php --> <div class="newsletter-signup"> <?= $page->renderEmailSignup(); ?> </div> Great! We've kept logic out of our code. We can render the field, and we can account for an empty value with a fallback. Unfortunately this is pretty limited in that it only handles a specific field, and it's implementation isn't as flexible as a component should be. We can fix that, and here are some new requirements to boot: Some templates may have multiple embed select fields which may or may not have a value Each embed select field is now paired up with a text field to add some content that appears with each form embed, think "Sign up for our newsletter today!" We want to render our mailchimp form embeds using the same component file, but handle different fields Sounds like a tall order, but it's a challenge easily overcome with page classes. We're going to introduce a new method called renderComponent that will be global, reusable, and very flexible. We're also going to make use of another very great ProcessWire feature to do it. Back to our DefaultPage class: <?php namespace ProcessWire; // /site/classes/DefaultPage.php class DefaultPage extends Page { // ...Other DefaultPage methods /** * Renders a file located in /site/templates/components/ with optional variables */ final public function renderComponent(string $file, ...$variables): string { $componentsPath = wire('config')->paths->templates . 'components/'; return wire('files')->render($file, $variables, ['defaultPath' => $componentsPath]); } /** * Renders either a selected form embed, fallback to default selected form */ public function renderEmailSignup(?string $embedSelectField = null): ?string { $settingsPage = wire('pages')->get('website_settings'); $embedField = $this->$embedSelectField ?: $settingsPage->default_email_embed; return $settingsPage->$embedField; } } We've done a couple of things here. We've updated renderEmailSignup to accept a field name, so now we're flexible on exactly which field select we'd like to check for a value on before falling back to default. We've also created a renderComponent method that is going to be super useful throughout the rest of our ProcessWire application. Our renderComponent receives a file name located in the components directory and any number of named parameters. You could change the $variables parameter to an array if you'd like, but I'm a big fan of the great features we have now in PHP 8+. Here's our refactored component file: <!-- /site/templates/components/newsletter_signup.php --> <?php if ($embedField): ?> <div class="newsletter-signup"> <?php if ($text): ?> <h2><?= $text; ?></h2> <?php endif ?> <?= $page->renderEmailSignup($embedField); ?> </div> <?php endif ?> And let's hop over to our (abbreviated) home page template: <body> <!-- ...Sections full of great content --> <section class="signup-call-to-action"> <?= $page->renderComponent('newsletter_signup.php', embedField: $page->embed_select, text: $page->text_1); ?> </section> <!-- ...Your awesome template design --> <section class="page-end-call-to-action"> <?= $page->renderComponent('newsletter_signup.php', embedField: $page->embed_select_2, text: $page->text_2); ?> </section> <!-- Your footer here --> </body> I don't know about you, but this is looking really good to me. The number of things we've accomplished while having written so little code is remarkable: Because we used wire('files')->render(), the entire ProcessWire API is available within the component, so now our renderEmailSignup method is too. The variadic function parameters (or array if preferred) let us pass an arbitrary number of variables to any component file, unrestricted future flexibility Variables are scoped to each component! There's no reference to template fields in our component that could break if changes are made No more PHP includes, we don't have to juggle paths or constantly repeat them in our code, nor rely on declaring variables before including a file. ProcessWire will throw an exception if we try to render a file that does not exist which makes locating issues very easy We'll also see an exception if we try to reference a variable in our component that wasn't passed which can also help troubleshooting. Notice that the renderComponent is final. We want that behavior to remain consistent everywhere we use it and not overwritten either intentionally or by accident on our inheriting page classes. We want to eliminate any confusion between templates by knowing it will always do the same thing the same way. We can explore other uses too, perhaps a renderPartial for files in /site/templates/partials where we store files like site_header.php. As mentioned above however, if a variable is expected in the rendered file but not included in our render method, we'll see an exception. Let's use site_header.php as an example because we're sure to run into situations where variables may or may not exist: <?php namespace ProcessWire; // /site/templates/partials/site_header.php ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?= $page->title; ?></title> <meta name="description" content="<?= $metaDescription ?? null; ?>"> <?php if ($includeAnalytics ?? true): ?> <script> // All that Google Analytics jazz </script> <?php endif ?> </head> <body class="<?= $bodyClasses ?? null; ?>"> <header> <?= $page->renderComponent('site_nav.php', includeEmailButton: true); ?> </header> Problem: solved. By using nullsafe ?? operators, we can call $page->renderPartial('site_header', description: 'The ultimate Spice Girls fan page.'); and never get errors for variables that may not be included when calling renderComponent, such as includeAnalytics, which now also has a default value of 'true'. Nice. We haven't even gotten to our actual page classes yet... Our templates are about to receive superpowers. Let's take our blog to the next level. In my comment on the other thread, I created a specific example of adding a readTime method to our blog posts, let's go one level higher to our blog.php template. We'll populate some methods up front and then talk about what we've done: <?php namespace ProcessWire; // /site/classes/BlogPage.php class BlogPage extends DefaultPage { /** * Get latest blog posts, optionally with/without pinned post, optionally in blog category */ public function latestPosts( int $limit = 3, bool $includePinnedPost = true, ?int $categoryId = null ): PageArray { $selector = 'template=blog-post'; if ($categoryId) { $selector .= ",blog_category={$categoryId}"; } $posts = wire('pages')->get($selector); if ($includePinnedPost) { $pinnedPost = $this->getPinnedPost(); if ($pinnedPost) { $posts->remove($pinnedPost); $posts->prepend($pinnedPost); } } return $posts->slice(0, $limit); } /** * Gets an optional pinned post if set/chosen * pin_blog_post A checkbox to indicate whether a post should be pinned * pinned_post A InputfieldPage field to choose a blog post */ public function getPinnedPost(): ?Page { if (!$this->pin_blog_post) { return null; } return wire('pages')->get($this->pinned_post); } } On our main blog page a user has the ability to choose whether a blog post is "pinned". A pinned post will always remain the first post anywhere a list of posts is needed, something like a big company announcement that the client wants to keep visible. These two methods alone have given us awesome abilities. For our main blog page, when someone visits our blog page, the most recent or pinned post is presented at the top, followed by the next two most recent posts, followed by two rows of 3 posts, for a total of 9. Let's assume that we've already created the BlogPostPage.php with the readTime method from my previous example. Here's our blog.php template <?php namespace ProcessWire; echo $page->renderPartial( 'site_header.php', bodyClasses: 'blog-page', metaDescription: $page->blog_description ); $posts = $page->latestPosts(9); $firstPost = $blogPosts->first(); ?> <section class="main-post"> <article> <img src="<?= $firstPost->blog_image->url; ?>" alt="<?= $firstPost->blog_image->description; ?>"> <h1><?= $firstPost->title; ?></h1> <?= $firstPost->summary; ?> <span><?= $firstPost->readTime(); ?></span> <a href="<?= $firstPost->url; ?>">Read More</a> </article> </section> <section class="recent-Posts"> <?= $page->renderComponent('blog_preview_card.php', blogPost: $posts->get(1)); ?> <?= $page->renderComponent('blog_preview_card.php', blogPost: $posts->get(2)); ?> </section> <section class="past-posts"> <?php foreach ($posts->slice(3, 6) as $post): ?> <?= $page->renderComponent('blog-preview_card.php', blogPost: $post); ?> <?php endforeach ?> </section> <?= $page->renderPartial('site_footer.php'); ?> So first off, we've really started to use our renderComponents method and component files. We also implemented a renderPartial as speculated upon above. Each does a similar thing, but having separate methods makes everything clear, handles paths, but still has a similar interface when calling them. A big thing to notice here is that at no point have we added any markup to our page classes, and no business logic to our templates. If we need to find anything, we know where to look just by glancing at the template. Ultimate maintainability. Here's our blog_preview_card.php component: <?php namespace ProcessWire; ?> <!-- /site/templates/components/blog_preview_card.php --> <article class="blog-preview-card card"> <img src="<?= $blogPost->blog_image->url; ?>" alt="<?= $blogPost->blog_image->description; ?>"> <h2><?= $blogPost->title; ?></h2> <div class="blog-summary"> <?= $blogPost->blog_summary; ?> </div> <span class="blog-read-time"><?= $blogPost->readTime(); ?></span> <a href="<?= $blogPost->url; ?>">Read More</a> </article> I am liking how well this is working out! Page classes have done a ton of heavy lifting here: We're using our renderComponent method to it's maximum potential and it's payed off in spades Our template couldn't be cleaner or more easily maintainable BlogPostPage.php has taken care of all of our needs as far as delivering the PageArray of posts and all our template does is output the data as needed Our "card" component will render the same thing everywhere and we can update how that looks globally with changes to one file If you don't think this can get more awesome, or think this post is already too long, I have bad news for you and you should stop reading now. Still here? Let's create a BlogPostPage class and add a method: <?php namespace ProcessWire; // /site/classes/BlogPostPage.php class BlogPostPage extends DefaultPage { // ... Other page methods, like readTime() public function relatedPosts(int $limit = 3): PageArray { return wire('pages')->get('template=blog')->latestPosts( limit: $limit, includePinnedPost: false, categoryId: $this->blog_category?->id ); } } The BlogPage::latestPosts method is really flexing it's muscle here. We've used it in two different places for different purposes but requesting similar data, blog posts. If you noticed, we're also specifying a category for this blog since we have a page select field that references a blog category. That was a parameter that we included back in our BlogPage::latestPosts() method. So, blog posts have a "You might also be interested in..." section with posts in the same category as the that one that a visitor has just read. With page classes this couldn't be easier to add, so let's use the relatedPosts method we just created in BlogPostPage.php in our blog-post.php template: <?php namespace ProcessWire; // /site/templates/blog-post.php echo $page->renderPartial( 'site_header.php', bodyClasses: 'blog-post', metaDescription: $sanitizer->truncate($page->blog_summary, 160) ); ?> <!-- The page hero, blog content, stuff, etc. --> <section class="related-posts"> <?php foreach ($page->relatedPosts() as $post): ?> <?= $page->renderComponent('blog_preview_card.php', blogPost: $post); ?> <?php endforeach ?> </section> <?= $page->renderPartial('site_footer.php'); ?> We've just added a related posts feature in *checks stopwatch* seconds. This project is going so fast that you can already hear the crack of the cold beer after a job well done. One more example, and I'll let you decide if this is too much, or feels just right. We want a blog feed on our home page. So before we go to the home.php template, let's do what we do (surprise, it's a page class): <?php namespace ProcessWire; // /site/classes/HomePage.php class HomePage extends DefaultPage { // Other HomePage methods... public function blogFeed(int $limit = 3): PageArray { return wire('pages')->get('template=blog')->latestPosts(limit: $limit); } } At first glance, this might seem like a bit much. Why create a method in our page class that is so short and simple? We could just call $pages->get('template=blog')->latestPosts(3) inside our template and get away with it just fine. Here's why I think it's worth creating a dedicated page class method: This creates yet another example of predictability between templates It promotes thie philosophy I like of page classes talking to page classes It's likely that we'll have other more complex methods in the HomePage class, keeping them together feels right and helps with uniformity- we always know where to look when seeing custom methods If we need to make a change to the BlogPage::latestPosts() method that affect how other page classes call that method, we don't have to root around in our templates to make any changes. It's pretty nice to see that thus far we have only ever referenced the $page object in our templates! There aren't any calls to $pages because our template is really about doing one thing- rendering the current page without caring about other pages. That's not to say that we can't, or shouldn't, use other ProcessWire objects in our templates, but it's still impressive how much we've been able to scope the data that we're working with in each template. I truly love the page classes feature in ProcessWire and even though this is a deeper dive than my other post, this really is still just scratching the surface because we can imagine having more complex behavior and other benefits. Here are some from my experience: Handling AJAX calls to the same page. Choosing how and what type of content is returned when the page is loaded is really nice. This can be done with hooks, but I really like page classes handling things like this in-context. Working with custom sessions between one or more pages. Creating a trait that shares session behavior between page classes is a great way to extend functionality while keeping it scoped. Adding external API calls and whatever complexity that may entail Provides the ability to add significant complexity to our templates in the admin yet little to no additional complexity in template files. The basic "pinned post" and form embed features are just the start As you can imagine, this makes replicating code you use often between projects trivial Page classes provide a home for logic that otherwise would be stuck in a template, or relegated to a messy functions.php file. No more functions.php ever. We met every single goal I listed here at the beginning Every single template thus far only uses if statements and loops DefaultPage could have a "bootApplication" method if needed that does things for every page and is called in ready.php. This is also a great way to create a "bootable" method in all of your page classes where bootApplication could call a bootPage method in your page classes if it exists. Thanks for coming to my TED talk. Hope you find this useful! If you have any questions, corrections, use cases, or things to add, the comments below are open and I'd love to hear them!
    1 point
  12. PW can't handle include decision for you. PW doesn't make any decision on templates and logik in front-end, you always have to provide an if-then and best way here is use simple includes for the view. You can specify a template file a page uses when rendering. But not for the page you're on, because it already has a template file your code is in and end in a recursion giving you an memory limit error. But you can do it for a page you're you are recieving from a find/get query and give it a template file before render it. For example: $gallery = $pages->get($id); if($input->urlSegment1 == 'view') { $gallery->template->set("filename","view_full_gallery.php"); $gallery->render(); } else { $gallery->template->set("filename","view_teaser_gallery.php"); $gallery->render(); } So this will render the gallery page with different templates depending on a condition. As you already seem to tried you could change the template file (not the PW template) of a page via a before page render hook.
    1 point
×
×
  • Create New...