Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/04/2022 in all areas

  1. I agree. However, to make a tutorial series complete, one needs to introduce the basics as well. Perhaps a concise but not too long overview would do the trick (especially if it links to all the official docs and blog posts in order to point out where to learn more about the basics). @3fingers In order to teach as much as possible in the shortest possible time, you might want to provide your learners an installable site-profile which does all the basics already, and you "just" finish it off by implementing the rest (which is everything beyond the basics). I would also pay for such a course, so that I can think outside of my box (and to support your efforts, of course).
    2 points
  2. With all the hype about ChatGPT, I wanted to see how useful it could be for us ProcessWire lovers. In a word: wow! It's pretty darn impressive for such early public testing and for such targeted subject. I love how it proposes code with comments, then proceeds to explain it. (Note: I've been getting more impressive and consistent results on mobile for some reason.) Prompt: Filter blog post by category in ProcessWire To filter blog posts by category in ProcessWire, you can use the find method of the $pages object, along with the category field and the equals operator, like this: // Get the category slug from the URL $category_slug = $input->urlSegment1; // Find all blog posts in the given category $posts = $pages->find("template=blog-post, category.slug=$category_slug"); // Loop through the posts and output their titles foreach ($posts as $post) { echo "<h2>$post->title</h2>"; } This code will find all blog posts that are in the category with the given slug, and output their titles. You can modify this code to output other information about the posts, such as their content, images, or dates. To make it easier for users to filter posts by category, you can also create a navigation menu that lists all the available categories, like this: // Find all categories $categories = $pages->find("template=blog-category"); // Output a link for each category echo "<ul>"; foreach ($categories as $category) { echo "<li><a href='/blog/$category->slug'>$category->title</a></li>"; } echo "</ul>"; This code will find all blog categories and output a link for each one, using the category slug as the URL parameter. When a user clicks on a link, they will be taken to the blog page with the posts filtered by that category. Prompt: Login form in ProcessWire To create a login form in ProcessWire, you can use the following code: // Check if form has been submitted if ($input->post->submit) { // Sanitize user input $email = $sanitizer->email($input->post->email); $password = $sanitizer->text($input->post->password); // Check if user exists and password is correct $user = $users->get("email=$email"); if ($user && $user->matches($password)) { // Login user $session->login($user); // Redirect to home page $session->redirect("/"); } else { // Output error message $error = "Invalid email or password."; } } // Output login form echo "<form method='post'>"; echo "<label>Email:</label>"; echo "<input type='email' name='email' value='$email'>"; echo "<label>Password:</label>"; echo "<input type='password' name='password' value='$password'>"; echo "<input type='submit' name='submit' value='Login'>"; echo "</form>"; // Output any errors if ($error) { echo "<p class='error'>$error</p>"; } This code creates a login form that accepts an email and password. When the form is submitted, it checks if a user with the given email exists, and if the password is correct. If the email and password are valid, it logs in the user and redirects to the home page. If the email and password are invalid, it outputs an error message. Prompt: User registration class in ProcessWire with email, password of at least 10 characters and age over 18. Check if email is unique. To create a user registration class in ProcessWire with email, password of at least 10 characters, and age over 18, you can use the following code: class UserRegistration { public function register($email, $password, $age) { // Sanitize user input $email = $sanitizer->email($email); $password = $sanitizer->text($password); $age = (int) $age; // Validate user input if ($age < 18) { $errors[] = "You must be over 18 to register."; } if (strlen($password) < 10) { $errors[] = "Your password must be at least 10 characters long."; } if ($users->get("email=$email")) { $errors[] = "A user with this email already exists."; } // If no errors, create user account if (!$errors) { // Create new user $user = new User(); $user->email = $email; $user->password = $password; $user->age = $age; // Save user to database $user->save(); // Redirect to confirmation page $session->redirect("/confirmation"); } } } This code creates a UserRegistration class with a register method that takes an email, password, and age as arguments. The method sanitizes and validates the input, and creates a new user if the input is valid. It also checks if a user with the given email already exists in the database, and outputs an error if one does. To use this class, you would first instantiate it: $registration = new UserRegistration(); Then, you can call the register method to create a new user: $registration->register($email, $password, $age); Prompt (similar to previous one): User registration form in ProcessWire with first name, last name, email, password of at least 10 characters and age over 18. To create a user registration form in ProcessWire with first name, last name, email, password of at least 10 characters, and age over 18, you can use the following code: // Check if form has been submitted if ($input->post->submit) { // Sanitize user input $first_name = $sanitizer->text($input->post->first_name); $last_name = $sanitizer->text($input->post->last_name); $email = $sanitizer->email($input->post->email); $password = $sanitizer->text($input->post->password); $age = (int) $input->post->age; // Validate user input if ($age < 18) { $errors[] = "You must be over 18 to register."; } if (strlen($password) < 10) { $errors[] = "Your password must be at least 10 characters long."; } // If no errors, create user account if (!$errors) { // Create new user $user = new User(); $user->first_name = $first_name; $user->last_name = $last_name; $user->email = $email; $user->password = $password; $user->age = $age; // Save user to database $user->save(); // Redirect to confirmation page $session->redirect("/confirmation"); } } // Output registration form echo "<form method='post'>"; echo "<label>First Name:</label>"; echo "<input type='text' name='first_name' value='$first_name'>"; echo "<label>Last Name:</label>"; echo "<input type='text' name='last_name' value='$last_name'>"; echo "<label>Email:</label>"; echo "<input type='email' name='email' value='$email'>"; echo "<label>Password:</label>"; echo "<input type='password' name='password' value='$password'>"; echo "<label>Age:</label>"; echo "<input type='number' name='age' value='$age'>"; echo "<input type='submit' name='submit' value='Submit'>"; echo "</form>"; // Output any errors if ($errors) { foreach ($errors as $error) { echo "<p class='error'>$error</p>"; } } Watch out, this is addictive 😃
    1 point
  3. Thanks Kogondo, I didn't see this comment. I just saw the one from November 20th talking about the version 0.2.8 on the dev branch. I just tried getMenuItems(1705, 1,['default_title' => 1]) and it works. Thanks again
    1 point
  4. Yes thanks. I think those elements must have dated from the early days of RockFrontend and I never updated that _main.php. So I've re-done it all now as per the latest readme and it all seems fine.
    1 point
  5. I can't remember for sure but I don't think so. I think it has always been injected automatically (as it was meant to be zero-setup from the very beginning) and I wanted to avoid having instructions in my readme that are necessary to make everything work. Is your problem fixed now?
    1 point
  6. Hi @bernhard: I tried to use this in a multisite environment, but /site/ is hardcoded in a few places rather than use of the $this->wire->config->paths->site value. In particular the StylesArray.php class where paths get passed to LESS methods, Also the excludeDefaults paths in LiveReload.php In the main RockFrontend.module there is hardcoding in the renderMatrix method - I haven't used it yet, but I noticed it going through. A way to reproduce might be an installation where you rename the /site/ folder to something else - as in multisite the different site folders are generally called something like 'site-domain' or something similar. I guess I am the only one who still has some multisite installations, but for some projects it make maintenance simpler and more consistent.
    1 point
  7. You don't have to support multisite with your tools - it just will make sense to mention that in your feature set. If a person installed multisite according to the tutorials/instructions provided on the PW site: https://processwire.com/docs/more/multi-site-support/ Under option #1 they typically will have a directory structure where their main website install is under /site/ and subsequent sites start in tmp/site and then are moved under /site-1/ /site-2/ or something similar. For example, a person installs a new /site-3/ and decides they want to try your front-end plugin. They add your module to /site-3/ and want to install a new uikit profile there. They might be shocked and upset to find their /site/ folders and files were modified. I'm guessing you'd hear about it.
    1 point
  8. 1 point
  9. Good Idea but if it is going to be paid then please only exclusive content, just for example applied api usage starting from a certain level such as building forms or applied arrays ... etc. etc. and going up level ... please not how to install processwire, output strategies, css frameworks and more of the same that is already out there all over the place and chewed over
    1 point
  10. Thanks for posting that faceted-search library. Going through the git info I really like what I read there. I will certainly post back in the forum about this lib.
    1 point
  11. The sanitizer method intended for text that will be used as a selector value is $sanitizer->selectorValue(). See for example in Ryan's demo skyscrapers site. By default this sanitizer will filter out the asterisk, presumably because it's a character used within some selector operators. But it looks like if you whitelist it in the $options argument and it will be retained and the error is avoided because the value gets wrapped in quotes. $q = $sanitizer->selectorValue($input->get('q'), ['whitelist' => ['*']]);
    1 point
  12. Have you already seen this library perhaps: https://github.com/k-samuel/faceted-search ?
    1 point
  13. A few months back I had the urge to try a lot of new things and one thing was a SSG (static site generator) called 11ty.dev and there was one channel and one website that made it super easy to start. https://www.youtube.com/@11tyRocks/videos https://11ty.rocks/ I liked it because it showed everything from start to "sure you can build an app with that". What I want to say is that even guides on how to install ProcessWire, make it more secure, or about hooks or how to "write your own module" would make perfect sense. There is more than enough courses could cover. As already mentioned... there are few bits and pieces out there, most of them are quite outdated or at least the ProcessWire backend already looks totally different which makes it awkward in some kind to watch those videos. A new fresh approach sounds really good. There are tons of topics your course or maybe even courses could offer and talk about. See @bernhard's videos. They are really great and in full detail while only talking about a specific module. Haven't thought it through but I personally would provide some basics at least (installation, file and folder structure, some best practices), then maybe something like building a blog or magazine (as mentioned already) and go from there. A blog could have a RestAPI, a custom RSS Feed, and, so, on... oh and there is always: SEO, Online Marketing and Affiliate Marketing. There could be courses about "Why ProcessWire is perfect for (or) How to do SEO, OM, AM with ProcessWire". Just outlined a few ideas out of my head. ProcessWire Basics Installation Security Migration Updates and Maintenance How to structure your project Dos and Dont's Import a HTML Template/Theme ProcessWire: Your First Real Project Blog/Journal/Magazine Member Area ProcessWire Advanced User, User roles, Access rights How to Hook How to Customize How to Whitelabel How to RestAPI/GraphQL ProcessWire as Headless CMS Use VUE, Angular, Svelte, AlpineJS with ProcessWire Your very first ProcessWire module How to structure your backend, fields and templates ProcessWire SEO PageSpeed Caching SEO-related Modules ProcessWire Setups Multi-User Setup Multi-Instance Setup Multi-Domain Setup ProcessWire Master Class ... ... ... My 2 cents for now.
    1 point
  14. Preventing a page from being moved is not necessarily a straightforward matter of trapping the change in a save hook in the same way as a page edit. A problem occurs if the page is only to be 'blocked' conditionally - when the page path is in some given array, for example. In hooking before page save, the page path is the new page path after the move, rather than before it, so you need to do something like this: // .... In the before page:saveReady hook // $page is the page :) The code below operates when (isset($page->parentPrevious) && $object->parentPrevious != $object->parent) $name = $page->parentPrevious->path . $page->name . '/'; // need the path before it was moved if(in_array($name, $blockedNames)) { // $blockedNames are the ones where we don't want moves // Because this hook operates after the move, we need to reverse the move $page->parent = $page->parentPrevious; // Alternatively, to completely stop the save //$event->replace = true; //$event->return = false; } //... rest of hook This prevents the page being moved, both in the page hierarchy (by dragging) or in the page editor by changing the parent in the settings tab. It is also possible to hook before Page:moveable with something like this /** @var Page $page */ $page = $event->object; $moveable = $event->return; // ... code to set $moveable to false if conditions met $event->return = $moveable; Interestingly, the (not documented?) moveable method is created as a hook by PagePermissions and so is hookable. However, this method appears to catch only the situation where the move is effected by dragging the page in the tree, not when the parent is changed in the settings.
    1 point
  15. Hi, I'm very happy to announce that processwire is finally available on turnkey. Here is the link https://www.turnkeylinux.org/node/32567 Turnkey offers production ready free open source server images, meaning that they give you servers already installed and configured ready to be facing the internet. You can now host your own processwire without having to install or configure it. Thanks, Have a good day !!
    1 point
  16. Latte is great indeed! I've been using it for all projects since discovering it. Everything is so much more concise and elegant, especially once your start building your own filters and macros. Quick note that you can also use Latte with Wanze's TemplateEngineFactory. I've found that the easiest way to get started; one composer install and you're ready to go ?
    1 point
×
×
  • Create New...