### ProcessWire Pagination Example Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt Demonstrates how to implement pagination in ProcessWire using the `find` method and `renderPager`. This is useful for displaying large lists of items, such as blog posts. ```php find("template=blog-post, limit=10, sort=-date"); echo $results->renderPager([ 'numPageLinks' => 10, 'nextItemLabel' => 'Next »', 'previousItemLabel' => '« Prev', ]); foreach($results as $post) { echo "
Additional content
"; // /site/templates/_main.php includes all the HTML wrapper ``` -------------------------------- ### ProcessWire Hooks: After, Before, and Replace Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt Demonstrates how to use after, before, and replace hooks in ProcessWire to modify return values, validate arguments, or completely override method behavior. These hooks are essential for extending ProcessWire's functionality. ```php addHookAfter('Page::render', function($event) { $page = $event->object; $event->return = str_replace( '', '
Page ID: ' . $page->id . '
', $event->return ); }); // Before hook - validate/modify arguments $wire->addHookBefore('Pages::save', function($event) { $page = $event->arguments(0); if($page->template == 'product' && !$page->price) { throw new WireException("Products must have a price"); } }); // Replace hook - completely replace behavior $wire->addHookBefore('Page::render', function($event) { $page = $event->object; if($page->template == 'maintenance') { $event->replace = true; $event->return = "
";
}
});
```
--------------------------------
### Create Symlinks for Multi-Tool AI Support (Bash)
Source: https://github.com/webmanufaktur/pwaiworkflow/blob/master/README.md
This script creates symbolic links from tool-specific directories (e.g., .claude/, .cline/) to the .agents/skills/ folder. This allows AI coding assistants that do not natively support the .agents/ directory structure to utilize the same skills.
```bash
./create-symlinks.sh
```
--------------------------------
### Basic ProcessWire Module Structure
Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt
Defines a simple 'Hello World' module for ProcessWire. This module implements the Module interface and provides a basic method. It requires ProcessWire 3.0.0 or higher and can be used by retrieving it via the modules API.
```php
'Hello World',
'summary' => 'A simple example module',
'version' => 100, // 1.0.0
'author' => 'Your Name',
'autoload' => false,
'singular' => true,
'requires' => ['ProcessWire>=3.0.0'],
];
}
public function hello($name = 'World') {
return "Hello, $name!";
}
}
// Usage
$module = $modules->get('HelloWorld');
echo $module->hello('ProcessWire');
```
--------------------------------
### ProcessWire Hooks: Adding Methods and Properties
Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt
Illustrates how to dynamically add new methods and properties to existing ProcessWire objects using hooks. This allows for custom logic and data retrieval without modifying the core classes.
```php
addHook('Page::summarize', function($event) {
$page = $event->object;
$maxLen = $event->arguments(0) ?: 200;
$event->return = wire('sanitizer')->truncate($page->body, $maxLen);
});
// Usage: echo $page->summarize(150);
// Add new property to Page class
$wire->addHookProperty('Page::intro', function($event) {
$page = $event->object;
$intro = strip_tags($page->body);
$event->return = substr($intro, 0, 255);
});
// Usage: echo $page->intro;
```
--------------------------------
### ProcessWire Autoload Module with Hooks
Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt
Demonstrates an autoloading module in ProcessWire that executes code on every request or specifically within the admin area. It utilizes the `ready` method to safely add hooks, such as logging page save events.
```php
'My Autoload Module',
'version' => 1,
'autoload' => true, // Loads on every request
// 'autoload' => 'template=admin', // Only in admin
];
}
public function init() {
// Early initialization - API may not be ready
}
public function ready() {
// API is ready - safe for hooks
$this->addHookAfter('Pages::saved', function($event) {
$page = $event->arguments(0);
$this->log->save('my-module', "Page saved: {$page->path}");
});
}
}
```
--------------------------------
### Process Image and File Fields in PHP
Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt
Demonstrates how to access, manipulate, and display images and files associated with a ProcessWire page. It covers iterating through multiple images, accessing single images, generating thumbnails with various resizing and cropping options, retrieving image properties, and filtering pages based on image and file attributes.
```php
images as $image) {
echo "";
}
// Single image field
if($page->image) {
echo "
";
}
// First/random image
$first = $page->images->first();
$random = $page->images->getRandom();
// Image resizing - cached automatically
$thumb = $image->width(300); // Proportional width
$thumb = $image->height(200); // Proportional height
$thumb = $image->size(300, 200); // Exact size (crops)
echo "
";
// Cropping options
$thumb = $image->size(300, 200, 'north'); // Top center
$thumb = $image->size(300, 200, 'southeast'); // Bottom right
$thumb = $image->size(300, 200, 'center'); // Center (default)
$thumb = $image->size(300, 200, '50%,30%'); // Percentage position
// Resize options
$options = [
'quality' => 90,
'upscaling' => false,
'cropping' => 'center',
];
$thumb = $image->size(300, 200, $options);
// Image properties
echo $image->url; // Full URL
echo $image->filename; // Server path
echo $image->width; // Width in pixels
echo $image->height; // Height in pixels
echo $image->description; // Description text
echo $image->filesizeStr; // "1.5 MB"
// Image tags (enable in field settings)
$featured = $page->images->getTag('featured');
$gallery = $page->images->findTag('gallery');
// File fields
foreach($page->files as $file) {
echo "$file->description ($file->filesizeStr)";
}
// Find pages by file properties
$pages->find("images.width>=800");
$pages->find("files.ext=pdf");
$pages->find("files.filesize>1000000");
```
--------------------------------
### ProcessWire Markup Regions for HTML-First Approach
Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt
Illustrates ProcessWire's Markup Regions feature, enabling an HTML-first approach to template development. Regions can be targeted for replacement, appending, or prepending content using `pw-append` and `pw-prepend` attributes.
```php
useMarkupRegions = true;
$config->appendTemplateFile = '_main.php';
// In template files, target regions by ID:
?>
This replaces the default bodycopy content.
``` -------------------------------- ### ProcessWire Core API Variables and Access (PHP) Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt Demonstrates how to access and utilize core ProcessWire API variables like $page, $pages, $user, and $input within templates and modules. It covers finding pages, accessing page properties, traversing page trees, and retrieving API services like sanitizer and session. ```php useFunctionsAPI = true; // Access pages - all equivalent methods $pages->find("template=product"); // Via API variable pages()->find("template=product"); // Via function pages("template=product"); // Shortcut // Get single page $contact = $pages->get("/about/contact/"); $product = pages("/products/hammer/"); // Common API variables $currentPage = $page; // Current page being viewed $allPages = $pages; // Find, get, save, delete pages $currentUser = $user; // Current logged-in user $input = wire('input'); // GET, POST, COOKIE, URL segments $sanitizer = wire('sanitizer'); // Input sanitization $session = wire('session'); // Session management $config = wire('config'); // Site configuration // Page properties echo $page->id; // Page ID echo $page->title; // Page title echo $page->path; // Full path: /parent/child/ echo $page->url; // URL with domain handling echo $page->httpUrl; // Full URL with scheme echo $page->template->name; // Template name echo $page->parent->title; // Parent page title // Page traversal $children = $page->children("limit=10"); $siblings = $page->siblings(); $ancestors = $page->parents(); $rootParent = $page->rootParent; // Access API in classes/modules class MyModule extends WireData implements Module { public function doSomething() { $pages = $this->wire('pages'); // Preferred in modules $user = $this->wire()->user; // IDE-friendly return $pages->find("template=product"); } } ``` -------------------------------- ### Define Fields and Templates with RockMigrations in PHP Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt This snippet demonstrates how to use RockMigrations to define custom fields (text, textarea, datetime, rich text, page reference, image, repeater) and templates within a ProcessWire project. It utilizes a fluent API for a structured approach to database and content structure management. ```php migrate([ 'fields' => [ // Text fields 'my_text' => ['type' => 'text', 'label' => 'Title'], 'my_textarea' => ['type' => 'textarea', 'rows' => 5], // Date field 'my_date' => [ 'type' => 'datetime', 'dateOutputFormat' => 'd.m.Y H:i', 'dateInputFormat' => 'j.n.y', 'datepicker' => 1, 'defaultToday' => 1, ], // Rich text (CKEditor) 'my_body' => [ 'type' => 'textarea', 'inputfieldClass' => 'InputfieldCKEditor', 'contentType' => 2, 'formatTags' => 'p;h2;h3;h4', 'toolbar' => 'Format, Bold, Italic, BulletedList, PWLink, Source', ], // Page reference 'my_category' => [ 'type' => 'page', 'derefAsPage' => 1, 'inputfield' => 'InputfieldPageListSelect', 'findPagesSelector' => 'template=category', 'labelFieldName' => 'title', ], // Image field 'my_image' => [ 'type' => 'image', 'maxFiles' => 1, 'extensions' => 'jpg jpeg png svg', 'maxSize' => 3, 'gridMode' => 'grid', ], // Repeater 'my_items' => [ 'type' => 'FieldtypeRepeater', 'fields' => ['title', 'body', 'image'], 'repeaterTitle' => '#n: {title}', ], ], 'templates' => [ 'product' => [ 'fields' => ['title', 'my_body', 'my_image', 'my_category'], 'sortfield' => '-created', 'parentTemplates' => ['products'], 'noChildren' => 1, ], ], ]); // Create roles with permissions $rm->createRole('editor', ['page-edit', 'page-view']); // Create pages with data using named parameters $rm->createPage( template: 'product', parent: '/products/', name: 'demo-product', title: 'Demo Product', data: [ 'my_body' => '
Product description
', 'my_category' => $pages->get('/categories/featured/'), ], ); ``` -------------------------------- ### ProcessWire Performance Optimizations: findIDs and findRaw Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt Demonstrates methods for optimizing ProcessWire queries by retrieving only necessary data. `findIDs` returns an array of page IDs, while `findRaw` returns an array of associative arrays containing specified fields, bypassing full page objects for better performance. ```php findIDs("template=product"); $data = $pages->findRaw("template=product", ["title", "price"]); ``` -------------------------------- ### ProcessWire Hooks: Custom Routing and Conditional Logic Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt Shows how to implement custom routing using URL hooks and how to apply hooks conditionally based on page templates or argument values. This enables flexible URL handling and targeted behavior modification. ```php addHook('/api/products/{id}', function($event) { $id = (int) $event->id; $product = $event->pages->get("template=product, id=$id"); if($product->viewable()) { return [ 'id' => $product->id, 'title' => $product->title, 'price' => $product->price, ]; } return false; // 404 }); // Conditional hooks - target specific page types $wire->addHookAfter('Page(template=product)::render', function($event) { // Only executes for product pages }); // Hook with argument conditions $wire->addHookAfter('Page::changed(status)', function($event) { $oldValue = $event->arguments(1); $newValue = $event->arguments(2); wire('log')->save('changes', "Status changed from $oldValue to $newValue"); }); ``` -------------------------------- ### ProcessWire URL Segments for Routing Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt Shows how to implement URL segment routing in ProcessWire templates. This allows different content or includes to be loaded based on URL segments, enabling cleaner routing. ```php Templates > [template] > URLs $segment = $input->urlSegment1; switch($segment) { case '': echo $page->body; break; case 'photos': include('./_photos.php'); break; case 'map': include('./_map.php'); break; default: throw new Wire404Exception(); } ``` -------------------------------- ### ProcessWire Direct Output Template Source: https://context7.com/webmanufaktur/pwaiworkflow/llms.txt A basic ProcessWire template file demonstrating direct output of page properties like title and body. This is the simplest method for rendering content. ```php