-
Posts
1,070 -
Joined
-
Last visited
-
Days Won
16
Everything posted by dotnetic
-
Hi Bernhard, you could just use an image tag inside of the body with object-fit. The advantage of this method is that you even could use different images for different resolutions if you want to. Another advantage is that you do not land in specifity hell because the style attribute has a very high specifity. I created a small codepen example, that you could use as a base: https://codepen.io/jmar/pen/oNmmJeB
-
Provide a way to define / save / sync fields in the code base
dotnetic replied to Rasso's topic in Wishlist & Roadmap
Welcome to our lovely community, Rasso. I hope you are enjoying the benefits of ProcessWire as much as I do. We had the discussion about replicating / syncing fields on the server many times. I use RockMigrations as a reliable and working module for this. You write code with migrations and they get executed as soon as you save the file and refresh the admin. A migration can be inside the site/migrate.php file, or in a migrate method inside of your custom module, or somewhere else. Here is a possible example of a migration: $rm->migrate([ 'fields' => [ 'body' => [ 'label' => 'Content', 'type' => 'FieldtypeTextareaLanguage', 'inputfieldClass' => 'InputfieldTinyMCE', 'tags' => 'generic', 'contentType' => 1, 'langBlankInherit' => 1, 'inlineMode' => 0, 'height' => 500, 'lazyMode' => 1, 'features' => [ 0 => 'toolbar', 1 => 'menubar', 2 => 'stickybars', 3 => 'spellcheck', 4 => 'purifier', 7 => 'pasteFilter', ], 'toolbar' => 'styles bold italic pwlink pwimage blockquote hr bullist numlist anchor code', 'rows' => 15, ], 'home_intro' => [ 'label' => 'Home Intro', 'type' => 'textarealanguage', 'tags' => 'generic', 'inputfieldClass' => 'InputfieldTinyMCE', 'rows' => 5, 'inlineMode' => 1, ], 'subheadline' => [ 'type' => 'text', 'inputfieldClass' => 'InputfieldTextLanguage', 'maxlength' => 100, 'tags' => 'generic', ], ], 'templates' => [ 'basic-page' => [ 'label' => 'Standardseite', 'fields' => [ 'title', 'navtitle', 'seo', ], ], 'imprint' => [ 'label' => 'Impressum', 'fields' => [ 'title', 'body', 'seo', ], ], ] ]); With the migration you can also create pages and even fill them with content (if you want that) $rm->createPage(title: 'About us', name: 'about-us', template: 'basic-page', parent: '/'); There is no sync between fields or templates you create in the admin and RockMigrations (there was a YAML option once, but I don't know if it still exists), but you get an easy to copy code in each fields edit section, that you can copy directly over to your migration. I am also in favor that migrations should be a core feature of ProcessWire, but Ryan does not approve. So we have to stick with what we have, and RockMigrations is a great solution. -
Latte: Create a comma separated list of items
dotnetic replied to dotnetic's topic in API & Templates
You could do that with latte also like so: {$pages->get('/')->children->each('title') | join(', ')} -
I am as many others love ❤️the Latte template engine, and I use RockFrontend to integrate it into ProcessWire. One cool feature of Latte is, that you can easily create a comma-separated (or any other separator) list of items, where the last item does not have a separator (comma) afterwards, without needing PHP. Take this code as an example {foreach $pages->get('/myparentpage')->children as $item} {$item->title|noescape}{sep}, {/sep} {/foreach} Which will output a list like: first title, second title, third title If you want to know more use cases take a look at the documentation at https://latte.nette.org/en/tags#toc-first-last-sep
-
This opens up so many possibilities for example for working with htmx or alpine.js. Thank you Ryan.
-
You don't need Docker Desktop for ddev to run at least on WSL or Linux (not sure about MacOS, but they recommend using Colima). You just can use the free open source docker-ce (docker engine).
-
I confirm this. This is one of the main benefits. Also every project can have its own configuration, for example if you need to run an old PHP or MySql version (which you shouldn't). Best part is, you can run the projects simultaneously.
-
To extend on Horst's answer: you could use a NOT selector with multiple ids separated by a pipe, to exclude them from the result like $expertises = $pages->find("template=case-type, sort=sort, ,id!=123|443|3035");
-
[solved] multiple URL hooks with named arguments not working
dotnetic replied to dotnetic's topic in General Support
Thx @bernhard So basically a simple regex. Facepalm that I did not thought of that myself ? -
AI often makes errors and once you tell them about its errors, it corrects itself. Had this on many occasions where I told the AI, that the information it gave me is not correct.
-
I have this URL hook (in an autoload module, but the same occurs if I use it in ready.php) and want to use named arguments, capturing the category and an article, like described in ProcessWire 3.0.173 core updates: New URL hooks: $this->wire->addHook("/textilien/{category}/{article}/", function ($event) { bd($event->category); bd($event->article); }); The hook only works if the url looks like https://mysite.com/textilien/hoodies/myarticle. It does not work if the URL is only https://mysite.com/textilien/hoodies/ or https://mysite.com/textilien/. Is it possible to make the category and article optional? Or do I have to create a URL hook for every of these possibilities (what I did for now).
-
Here is what I tried. Removed all site modules from the to be included instance (shop). Did not work. Also remove all site modules from the instance (web) where I try to include the first instance (shop). Did also not work. The error still occurs even with no modules at all. I am pointless at the moment, so I am going further with the url hooks approach.
-
@MarkE I don't know what you are referring to, but the post you linked is about multilingual websites. I am talking about multi-instance (including data of one PW into another).
-
As this is not working right now and I need to proceed, I have chosen to use url hooks ProcessWire 3.0.173 core updates: New URL hooks instead, and provide an API where I pull the data I need via AJAX. Anyways I would be interested in solving the issue with multi-instance.
-
Why is this ? showing on an empty template file
dotnetic replied to eutervogel's topic in General Support
Please post the content of your template file where the error occurs. Do you prepend or append files to the template? I think this might be the cause. Go to your template in ProcessWire and to the files tab. Disable prepending and appending any files, and see if that fixes the error. -
I am using How to use multi-instance in PW 3.x (processwire.com) to connect two PW instances, because I need to display data from one instance in the other. But when using this code in one of my template files in the second instance, <?php $shopSite = new \Processwire\ProcessWire('../../../fugamo-shop/dist/'); I get the following error https://fugamo.ddev.site/textilien/ Compile Error: Cannot declare class ProcessWire\InputfieldFieldsetOpen, because the name is already in use (Row 0 in /var/www/html/fugamo-shop/dist/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module) It works with two fresh PW instances, but not with my existing sites. I really don't know where to look to debug this. As you can see the PHP template file does not use a namespace. But even when using the namespace it does not work. I disabled template compilation in the settings, and also disabled automatic prepending/appending of _header.php and _footer.php Some more info, the site I try to bootstrap has many modules and fields and templates installed. The site where I try to include it in, just has a few modules installed and not many fields. ProcessWire version ist the latest dev 3.0.222 in both instances.
-
[Closed] How to disable sort in a find or findRaw query?
dotnetic replied to dotnetic's topic in API & Templates
This is really cool and does exactly what I want. Thx. -
[Closed] How to disable sort in a find or findRaw query?
dotnetic replied to dotnetic's topic in API & Templates
Thanks for your help, but I was a bit unspecific in my request. I actually want a findRaw and only query some fields of these pages, because it is much faster. And so getByIDs would not help me. Or can I combine it somehow with findRaw? -
[Closed] How to disable sort in a find or findRaw query?
dotnetic replied to dotnetic's topic in API & Templates
Here is my articleSelector in action. articleselector.mp4 -
[Closed] How to disable sort in a find or findRaw query?
dotnetic replied to dotnetic's topic in API & Templates
Yes, sure. I have my custom tabulator.info integrated to select which products in which order should appear in a category of a shop like "shirts for boys, single color", "shirts for girls, multicolor", "caps", "hoodies" and more. On the left you see a tabulator with all available products. When clicking a product, it is moved to the right tabulator, which displays the selected products. Then you can reorder the products in that second tabulator via drag and drop. When saving the page the id's and their order are saved to another field (selectedarticles). Later on the frontend, the products in this category should be displayed in the manually specified order. Sure, I could have created pages for this, but this would produce much overhead (as I have many categories and for each category you can choose which products and in which order) and I only need a reference to the original product page. I did something similiar like your example code, but it would be nice, if ProcessWire would provide a sort=false option or something similar to retain the order. -
[Closed] How to disable sort in a find or findRaw query?
dotnetic replied to dotnetic's topic in API & Templates
I don't want a reversed sort order. I want to retain the order of the id's that i specified. Take this query for example. $pages->find('id=8|3|4|2|20|2'); I want to get the pages in this order: 8,3,4,2,20,2 -
I want to find an array of pages in a specified order, but it seems that ProcessWire by default sorts ascending by ID, but I want to preserve the order in my query. Is there a way to do this? My query looks like this: $articles = $pages->find('id=4|2|1'); which gives me the result in this order: 1,2,4
-
Congratulations. A problem nowadays is, that people complain and ask questions before trying out things themselves and realize that it took way less time to set things up, then writing and asking.
-
I recommend using Rector for upgrading legacy code or modules. I have written a short introduction/tutorial how you can use it here: You can then select which files or paths should be updated and to which PHP version and it does automated safe refactoring on them. Most of the plugins should then work out of the box with PHP 8, I have converted several modules with it. New rulesets for rector are published whenever they are needed. It is a great tool.
-
Introduction to RectorPHP In the dynamic world of PHP development, code refactoring is an inevitable task, whether for code optimization or transitioning to newer PHP versions. RectorPHP stands as a vital tool, simplifying this often challenging process. So, what is RectorPHP? What is RectorPHP? RectorPHP, or Rector, is a revolutionary open-source tool created to automate the process of refactoring PHP code. Refactoring, in simple terms, refers to the modification of a software system's internal structure without changing its external behavior, ultimately leading to enhanced readability and maintainability. Built on the powerful PHP Parser library, Rector analyzes and manipulates PHP code at the abstract syntax tree (AST) level. This granular control allows for intricate adjustments, making refactoring a breeze. But Rector's capabilities don't end here. Its true strength lies in its role as an automatic code upgrade tool. RectorPHP as an Automatic Code Upgrade Tool RectorPHP's primary role is to transition PHP code from legacy standards to modern, efficient, and more secure versions. This transformation allows developers to maintain their codebase up to date, benefiting from the latest advancements in PHP development. How Can RectorPHP Upgrade Your PHP Code? RectorPHP provides a smooth and efficient roadmap to upgrade old PHP code to contemporary versions. Here's how: Installation The first step is to install Rector in your project. Given it's a composer-based project, installing is as simple as running composer require rector/rector --dev in your terminal. Configuration Next, Rector requires a configuration file (rector.php) to instruct it on what to refactor. This file, located at the root of your project, should specify the rule sets Rector should adhere to. For instance, the following configuration upgrades PHP code to PHP 8.1: <?php declare(strict_types=1); use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/src' ]); // register a single rule $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); // define sets of rules $rectorConfig->sets([ LevelSetList::UP_TO_PHP_80 ]); }; Refactoring With Rector installed and configured, it's time to initiate the refactoring process. Execute vendor/bin/rector process in your terminal, and Rector will begin refactoring your code, illustrating the changes as it progresses. Review and Test While Rector often delivers flawless results, it's still a good practice to examine the modifications it makes. Ensuring that the changes conform to your project's requirements and haven't led to any unforeseen behaviors is a smart move. To further ascertain that your system's functionality remains unscathed, it's advisable to run your test suite. Remember, these steps aren't strictly necessary, but they add an extra layer of safety to your refactoring process. Rector also provides a "dry run" feature, where it displays the proposed changes without actually modifying the codebase. This feature is useful to preview what Rector will do before allowing it to alter your project. Conclusion RectorPHP is an essential tool for PHP developers looking to modernize their codebase efficiently. By simplifying the refactoring process and offering a seamless upgrade path for transitioning to more recent PHP versions, Rector empowers developers to focus on crafting high-quality software. Utilizing Rector means keeping your PHP code in sync with the rapidly evolving landscape of PHP development.
- 1 reply
-
- 13