-
Posts
192 -
Joined
-
Last visited
-
Days Won
3
Everything posted by markus_blue_tomato
-
People buying 4 things in crazy amounts: noodles, rice, toiletpaper and BEER ?
-
In Austria the whole thing becomes creepy. schools closed, event/restaurants with more than 100 people are not allowed, borders to italy closed, other countries closed border to Austria, gov. want's that companies should make homeoffice etc. Our company make home office beginning tomorrow.
-
How does it affect your dev life? Do you have less costumers? Do you make more Home Office?
-
SOLVED: Set value to custom image field via API
markus_blue_tomato replied to markus_blue_tomato's topic in General Support
Oooh - Thanks that was my problem: I have set the value on the image field and not on the image file! This works: if($language->id == $languages->getDefault()->id) { $page->images->findOne("basename=xyz.jpg")->set("my_custom_image_field", "test default language"); } else { $page->images->findOne("basename=xyz.jpg")->set("my_custom_image_field__{$language->id}", "test language {$language->name}"); } -
SOLVED: Set value to custom image field via API
markus_blue_tomato replied to markus_blue_tomato's topic in General Support
I found this new "setFieldValue" function in the pw dev commits: https://github.com/processwire/processwire/commit/573048abb4a6bdec77aee2cbff7d5837de857a05#diff-b4e6cafb51396ac6ada1a538da0ddc8cR639 I tried following: if($language->id == $languages->getDefault()->id) { $page->images->setFieldValue("my_custom_image_field", "test default language"); } else { $page->images->setFieldValue("my_custom_image_field__{$language->id}", "test language {$language->name}"); } I get no error, but all fields are still empty ? I will continue my investigations... Maybe @ryan has an idea? Also strange: the function should return true or false but if I dump the return of setFieldValue, I get only an empty string back. -
SOLVED: Set value to custom image field via API
markus_blue_tomato posted a topic in General Support
I'am working on a migration script from the ImageExtra Module to the new Custom Image Fields feature in ProcessWire. I have some problems while setting a field value to the new custom image field. I have set up the custom field and it works correct in the admin panel but not via the API: $page->images->my_custom_image_field = "test"; $page->save(); Results into: Fatal error: Uncaught ProcessWire\WireException: Item 'my_custom_image_field' set to ProcessWire\Pageimages is not an allowed type in /var/www/html/wire/core/WireArray.php:458 -
Some possebility to fold/expand duplicates in the log view would be great.
-
I found a solution which works: //users current language is for example: german // language "default" is english $key = "lorem_ipsum"; $string = __($key, "path/to/my/textdomain.php"); if($key == $string && wire('user')->language->name != "default") { wire('languages')->setLanguage('default'); $string = __($key, "path/to/my/textdomain.php"); wire('languages')->unsetLanguage(); } echo $string;
- 1 reply
-
- 2
-
Is it possible to get the value of a specific language in ProcessWire's translation tools? What I want to is following: Before printing out $key as fallback, I want to use a "fallback" language. Only after the fallback language has also no result, the $key should be printed out. //users current language is for example: german $key = "lorem_ipsum"; $string = __($key, "path/to/my/textdomain.php"); if(empty($string)) { $string = __($key, "path/to/my/textdomain.php", "english"); } echo $string; And yes I know I could put the fallback into the code as key, but I don't want this. If the fallback has to change, the customer can't do it on his own and I have to to this with a full deployment.
-
@Wanze I ended up in using your solution but to avoid writing the key everytime in two files per hand I created a node.js script which is executed in my build script of the whole project. The scripts reads all translatable strings from my .tpl files which look like this {translate}Lorem Ipsum{/translate} and creates in every view-directory a translation.php file. If anyone needs it here is the code of the node.js module (you have to install async and glob via npm..) "use strict"; const glob = require('glob'); const async = require('async'); const fs = require('fs'); // find all directories glob("site/templates/views/**/", null, (error, directories) => { // iterate in paralell over directories async.each(directories, function(directory, directoryCallback) { // find all template files in the current directory glob(`${directory}*.tpl`, null, (error, templateFiles) => { if(error) return directoryCallback(error); let translationKeys = []; // iterate in paralell over templateFiles async.each(templateFiles, function(templateFile, templateFileCallback) { fs.readFile(templateFile, (error, data) => { if(error) throw err; let tpl = data.toString('utf8'); // find all keys let pattern = new RegExp('{translate\}(.+?)\{\/translate\}', 'gm'); let result = tpl.match(pattern); if(result && result.length > 0) { // extract key without smarty block syntax // transform it to PHP syntax result = result.map(item => item.replace(pattern, '__("$1");')); // push all keys to the collector of all keys in the current directory translationKeys.push(...result); } templateFileCallback(); }); }, function(error) { if(error) console.log("Error in the templateFiles logic", error); // executed after alle keys are collected from the tpl files in the current directory if(translationKeys.length > 0) { // filter duplicates // sort alphabetical translationKeys = [ ...new Set(translationKeys) ].sort(); // make the final PHP file let phpFile = [ '<?php namespace ProcessWire;', ...translationKeys ].join("\n"); fs.writeFile(`${directory}translations.php`, phpFile, 'utf8', function(error) { if(error) throw err; directoryCallback(); }); } else { directoryCallback(); } }); }); }, function(error) { if(error) console.log("Error in the directory logic", error); // all done exit the process process.exit(); }); });
-
Hello! I am working on a pull request, to make Smarty and Twig templates translatable within ProcessWire. I stuck a little bit at the RegExp patterns. Maybe some RegExp-Professional want's to help me? :-) Should be possible in Smarty files: {$this->__('text')} {__('text')} {_x('text')} {_n('text')} Should be possible in Twig Files: {{ $this->__('text') }} {{ __('text') }} {{ _x('text') }} {{ _n('text') }} The whole patters are in the parseFile Function: https://github.com/processwire/processwire/blob/341342dc5b1c58012ae7cb26cffe2c57cd915552/wire/modules/LanguageSupport/LanguageParser.php#L120 /** * Run regex's on file contents to locate all translation functions * */ protected function parseFile($file) { $matches = array( 1 => array(), // $this->_('text'); 2 => array(), // __('text', [textdomain]); 3 => array(), // _x('text', 'context', [textdomain]) or $this->_x('text', 'context'); 4 => array(), // _n('singular', 'plural', $cnt, [textdomain]) or $this->_n(...); ); if(!is_file($file)) return $matches; $data = file_get_contents($file); // Find $this->_('text') style matches preg_match_all( '/(>_)\(\s*' . // $this->_( '([\'"])(.+?)(?<!\\\\)\\2' . // "text" '\s*\)+(.*)$/m', // and everything else $data, $matches[1]); // Find __('text', textdomain) style matches preg_match_all( '/([\s.=(]__|^__)\(\s*' . // __( '([\'"])(.+?)(?<!\\\\)\\2\s*' . // "text" '(?:,\s*[^)]+)?\)+(.*)$/m', // , textdomain (optional) and everything else $data, $matches[2]); // Find _x('text', 'context', textdomain) or $this->_x('text', 'context') style matches preg_match_all( '/([\s.=>(]_x|^_x)\(\s*' . // _x( or $this->_x( '([\'"])(.+?)(?<!\\\\)\\2\s*,\s*' . // "text", '([\'"])(.+?)(?<!\\\\)\\4\s*' . // "context" '[^)]*\)+(.*)$/m', // , textdomain (optional) and everything else $data, $matches[3]); // Find _n('singular text', 'plural text', $cnt, textdomain) or $this->_n(...) style matches preg_match_all( '/([\s.=>(]_n|^_n)\(\s*' . // _n( or $this->_n( '([\'"])(.+?)(?<!\\\\)\\2\s*,\s*' . // "singular", '([\'"])(.+?)(?<!\\\\)\\4\s*,\s*' . // "plural", '.+?\)+(.*)$/m', // $count, optional textdomain, closing function parenthesis ) and rest of line $data, $matches[4]); return $matches; }
-
Weekly update for October 4th, 2019
markus_blue_tomato replied to ryan's topic in News & Announcements
?? -
yes, the frontend was not affected ?
-
@Wanze haha awesome - I had checked the sitemap generation in the module config but I don't use it and the path is not writeable. after upgrading I got the error message and unchecked it. now my pw adminpanel runs 100 times faster.... ? and I thought the slowness would be normal with this amount of fields/templates/pages ?
-
Access WireHttp Class over CLI
markus_blue_tomato replied to markus_blue_tomato's topic in General Support
aaah, the missing 'namespace ProcessWire;' was the problem. thx! -
I try to access wie WireHttp Class in a script executed on the command line but I'm failing hard and don't know why. Access to the Pages Class works well. <?php // include PW API include(__DIR__ . "/index.php"); var_dump($wire->pages); var_dump($wire->http); php test.php object(ProcessWire\Pages)#172 (0) { } NULL Does anyone know why? ? I tried also new WireHttp(), wire('http'), $http...
-
We use Nginx. But the ProcessWire Site is non public.
-
How would you map the Firebase data? Each collections / document would represent a page in pw? So you would need some kind of sync tasks which are triggerd on save / trash / publish and maybe a full sync job x times. And what should be the single source of truth? Firebase or ProcessWire?
-
Perfomance Question - Many records less data
markus_blue_tomato replied to mr-fan's topic in Dev Talk
I experimented with my weather station some with InfluxDB (https://www.influxdata.com/). Great for big time series data. But if you need the data in PW you will have some extra work ? -
How to pass all API variables to $files->render() ?
markus_blue_tomato replied to bernhard's topic in General Support
Use wire('all') Example from our production code: $factory = $modules->get('TemplateEngineFactory'); echo $factory->render('chunks/bodyCta.tpl', array_merge( (array) wire('all'), (array) [ "title" => $title, "text" => $text, "href" => $href ] )); -
Show field only when page status is published
markus_blue_tomato replied to markus_blue_tomato's topic in General Support
ok, thank you for the clearification ? -
Hi, Do anyone know how to show only a field, if the page is published? I tried `status=published` but this did not work. The field keep invisible also when the page is published.
-
Sounds nice, we built some similar (but highly customised on some special internal needs...). But found many very similar things in it. ?
-
$page->meta() ties data to the page its used on.
markus_blue_tomato replied to EyeDentify's topic in API & Templates
Hmm, I think it's very clear because it's a method from $page. Everything you do from $page are tied to the page itself.