-
Posts
720 -
Joined
-
Last visited
-
Days Won
3
Everything posted by froot
-
OK thanks for the input, it helps. I stick with markup regions and just "include" _head.php and _foot.php in the _main.php rather than using markup regions in this case (i.e. <div id="head">) or prepending/appending. But why did I even start want to change that? Because I'm hooking the page-object to add a ->fulltitle and a ->shorttitle method. the full title is $page->parent->title.'/'.$page->title; and will be used for the snipcart-basket. And the shot title is $page->title and will be used for the breadcrumbs to avoid redundancies. I thought the hooks kind of store whatever I tell them to store before anything else renders. Now I realise the value they return is composed at the moment the method gets called. So on the product-page I put: $product->title = $page->title; // which is the full title And since the _main.php renders last and that's where my _breadcrumbs.php is included, the ->shorttitle method thinks the ->title is the fullttitle and basically overwrites what the hook is doing. I hope I made myself clear. Solutions could be to not set $product->title = $page->title but I don't know any other way to change the title that gets sent to the cart. Or, include the breadcrumbs on _init.php ? But then it's above all the content… Store it in a variable on _init.php and return on _main.php? I had a working version where I basically manually composed on each page it's required what my ->fulltitle hook is doing and then disassemble it manually with standard php to accomplish what my short-title hook is doing. I thought using hooks would make this matter simpler, now in doubt. Thanks for further help!
-
it's actually astonishing how far I got while not thinking too much about this detail. I re-read the whole output strategies documentation, I say re-read because I did before, it probably just was too much to take in at once. I have been using Markup Regions, it gives me the best of both worlds, just as it states. I also appreciate the fact that I can thereby escape the php-syntax highlighting in my editor when there's a lot of HTML-markup in the template file and have it show HTML-syntax-highlighting instead and still delay the output. I also put $config->prependTemplateFile = '_init.php'; $config->appendTemplateFile = '_main.php'; $config->prependTemplateFile = '_head.php'; // this I added now $config->appendTemplateFile = '_foot.php'; // this I added now $config->useMarkupRegions = true; $config->useFunctionsAPI = true; in the config.php file and remove the head and foot section from the _main.php file. Now I get the error: Call to undefined function ProcessWire\ukIcon() which I reckon is just one of many functions. If I add include '_head.php' to the top of whichever template, everything works fine, just not the prepending (and possibly appending) on config file. What could be the reason? What am I missing? As much as I enjoy programming, I dislike this guessing around for hours and days so I turn to the forum. Does the order of the $config->prependTemplateFile-included files matter? Does in the above scenario _init.php get included before _head.php or vice versa? Thanks for help!
-
I got the empty-body requirement working, simply with a selector like ("body!=") – works fine. However, still struggling to return results in one language on another language, i.e. showing german results with no empty body on the english site. I followed this advice: and here's my code $language = $user->language; // save the user's language $languages = $page->getLanguages(); $user->language = $languages->get("de"); // returns 'Deutsch' $descendants = $page->descendants("template=cast, body!="); $total = count($descendants); $total = "(".$total." ".__('events').")"; echo $user->language->title.' '.$total; // returns 'Deutsch: (0 events)' when on english page :( $user->language = $language; // restore the user's language but it still doesn't work. Any ideas? I don't know how to select the german version of the page nor how to loop them.
-
OK I fixed it considering all the above. For some reason I always thought _main.php is prepended ?, maybe because that's where my <header> and <head> (meta data), navigation menu and whatnot is located and I got pretty far with that wrong assumption. It's still puzzling though, because I always put a <div id="content"> on _main.php which is then replaced by what comes after, i.e. what's on the template files with that same id.
-
I get an "Undefined Variable" Error on a template for a variable that I declare on the _main.php template which is clearly included. Some background: At the beginning I didn't have a _main.php template for that particular project because I started off with a different profile but all my other projects work that way so I just created one and yes also included it on the config.php… $config->prependTemplateFile = '_init.php'; $config->appendTemplateFile = '_main.php'; $config->useMarkupRegions = true; $config->useFunctionsAPI = true; Might there be something that am I doing wrong or missing out on though? Also, not sure if related, when I include "namespace ProcessWire" on the top of the template, cause I thought that might be the issue, it wouldn't know the functions like __() and _x(), you know, the ones to make strings multilingual. Call to undefined function _x(), did you mean _()?
-
yes, $magazine was a stupid typo. It needs to be $page, I think, because I'm on the page when the event happens – am I right? Now I put: $wire->addHookAfter('Inputfield(name=snipcart_item_image)::savedPageOrField', function($event) { $page->setAndSave('imagecolorat', '123456'); }); I put this code on the template of the page where the mentioned field 'snipcart_item_image' is. I then edit a page that uses that template in the CMS i.e. upload a new image to that field and save. The hook is supposed to set the value of the other field called 'imagecolorat' to '123456', but it doesn't.
-
Though my profile says "senior" I still consider myself a newb when it comes to PW and an intermediate when it comes to php. Nevertheless, I'm now trying to figure out hooks cause I have some actions to take place when something else occurs. So far I've been able to solve this with simple if-conditions. E.g. whenever a page with a specific template is created, it will always have a child page, the name of which will always be the same. So I just code if it doesn't exist with that name, create one, else do nothing. Not sure if that's the most elegant way but it does the job. Now it gets trickier. I want to reset the value of a certain field of a page upon image upload. I went through the documentation for hooks but it's confusing, again, I'm not exactly a pro so I might need a more for-dummies-approach. Not sure what's the difference between… $wire->addHookAfter(…) $this->addHookAfter(…) // is that inside my own function? $page->addHookAfter(…) and don't get me started on own hookable methods. Again, I'm still far from being an expert, but to my undestanding, you can hook a method of PW objects and add your own function to run before or after that method – makes sense to me. But creating your own hooable method? Why would you want to make a method hookable if it's your own creation? Can't you just change the method without touching the core? But that goes beyond my humble requirements anyway, just trying to understand the basics above ($wire, $this, …) Here's what I need particularly: $wire->addHookAfter('Inputfield(name=snipcart_item_image)::changed', function($event) { $magazine->setAndSave('imagecolorat', '123456'); // just to test }); So once I figured out how hooks work I might ditch the said if-conditions and use hooks instead. Thanks for help!
-
switch the language inside the foreach so it switches the user's language each time it returns the variable? The thing is, we might add more languages later, so I'd like to find a solution that will include all the languages from the get go.
-
Thanks for hints, it works but not always. Anyhow, what I'm trying to do is to return the number of descendants (with a non-empty body-field) for each language on the same page. Here's what I'm doing… foreach($languages as $language) : $hreflang = $homepage->getLanguageValue($language, 'name'); $url = "/$hreflang/$page->name/"; $descendants = $pages->get($url)->descendants("template=cast, body!="); $total = count($descendants); $total = "($total events)"; <a hreflang="<?=$hreflang;?>" href="<?=$url;?>"><?=$language->title; ?></a> <?=$total;?> endforeach; Somehow it ignores the specific path I'm using to find the descendants and translates it to the currently active language, thus returning the same results for each language. I can tell because when I echo all the results… foreach ($descendants as $d) : echo $d->url; endforeach; it always returns: /en/page-name/ and never /de/page-name/ Am I at least right in my assumption? Thanks for help!
-
which selector would select all items where a certain field is not empty? foreach ($items as $item) : echo $item->numChildren("body!=''"); endforeach; I think it's clear for a human just by looking at this what I'm trying to do, doesn't work though. I have to add, it's a multilingual field so the same field in another language might not be empty, not sure that's relevant though… Thanks for help!
-
wire404() doesn't work, localhost redirected you too many times.
froot replied to froot's topic in API & Templates
Maybe my question should be much more general. When I say "pages" I should probably say "posts" because technically that's what they are. They are sorted by date, listed on the parent page and when you open them you see them in detail. I have 2 languages, english as default and german, and the posts can be in english OR in german but (probably) never both, so they should only be listed on the appropriate language version. How can I accomplish that since, like I mentioned, I can't "turn off" the default language for the posts individually (change the status to not-active in its settings), only german? -
I have different pages, some of which have german and others have english content. The default language of the website is english. I want to show only german content when on the german site (/de/) and english when on the english site (/en/). I could deactivate a german page in the page's settings when needed but I can't just deactivate the english version in some cases cause it's the default language, so that's not the right way. I put a selector-field on the page's template with which the page's language is selected and managed to have at least the overview of pages (one level above) to only display what matches the currently viewed language. But what about the page-view itself? I thought I put an if-condition on the page's template itself and if the page's language matches the currently viewed language, it either displays the content or "throws" a 404error. Is that a good way to go about this issue? Anyway, it doesn't work as expected, I get This page isn’t working localhost redirected you too many times. Here's my code… if ($page->linguafranca->title != _x('en', 'HTML language code')) : wire404(); else : // content goes here endif; Thanks for help!
-
[SOLVED] answering my own thread, maybe it'll help someone in the future. I went with: foreach ($works as $work) : if ($all_categories->has($work->category) == true) : // put markup here endif; endforeach; …which works as a charm, cheers!
-
I have pages with multiple "categories". Those categories derive from a multiple value selector field. I want to be able to turn on or off single categories in general, so that when I do, the pages that have that category will not be selected when I select them (unless the page in question belongs to another category that is active.) Hope I made my point clear? So I put the selector field on the parent page as well. How can I manipulate the array according to whichever values are selected on the parent-page? either with selector? something like… $all_categories = $pages->get('/portfolio/')->get('category'); $works = $pages->get("template=work, category=$all_categories") // compare array on page with the array on the parent page or first compare the two arrays and build another array where I only add the results where the array intersect. So I think what I'm asking is: what is the API-equivalent for array_intersect to use with a WireArray?
-
I did of course check the markup in the browser, the text from the link was outside the container it should be in, very weird. What worked for me was to simply delete the CKEditor-summary field altogether and use a body field instead. Don't know why but with that the issue was gone. So I won't investigate it further and just file it under bugs. Thanks anyway!
-
inserting links i.e. <a>-elements, and only links, inside a CKEditor-summary field outputs the link-text and a weird " /> above the content-div (I'm using markup regions). I have no idea where this is coming from, all the other tags work perfectly, and the CKEditor-markup is fine too when adding links. It puts the <a>-element inside a <p> element but should be alright? Any hints?
-
I'm trying to assign a new parent to a set of pages according to a field of the page and the title of the new parent. $some_pages = $pages('template=template_name'); foreach ($some_pages as $sp) { $new_parent = $sp->some_field->title; // selector field $sp->of(false); $sp->parent = $pages->get("name=$new_parent"); $sp->save(); $sp->of(true); } This code works fine except when it doesn't ? which is when there's a ÄÖÜ or whatnot in the title, then I get an Exception: Unrecognized operator: & Error. I reckon that is because the browser receives e.g. Ü and turns it into Ü. But now it's all on the server and doesn't get converted? I guess the value in the mentioned field and of the title of the new page both store an Ü ? I always and still struggle with this kind of problems. $new_parent = htmlspecialchars($lc->club_region->title); // Ü This doesn't work either, now the browser just shows me how it's stored, pointing out the very problem but no solution. Thanks for enlightments.
-
but isn't the currently used PW-version CKEditor 4? What about CKeditor 5?
-
I actually went on with @dynweb's advice and am now working with Repeater-Matrix. That works like a charm! Thanks everyone.
-
OK I installed the AOS module and added CKEditor content templates to the body field. It seems to get closer to what I need. Still though, how can I create my template to select when selecting from the templates list?
-
it's already inside a repeater-field so it would be a repeater field inside a repeater-field :-/
-
I doubt nobody has seen this issue before… when I have an <h2> or <h3> or the likes in a CKEditor-body-field and I delete that header, the h-tag is applied to whatever comes next in line. I'm obviously talking about the WYSIWYG-view. Similar bugs occur when applying an h-tag, that tag sometimes encloses the next line as well. Could be that this happens when the next line is in the same "block"-element and not technically a new line but separated with a <br> but not always… When will a new version of CKEditor for PW be released or what's a competitive alternative at this point?
-
Thanks, I made significant progress using the mentioned thread. Still some issues… 1. file sizes Uploading a file (or a total of files) larger than setMaxFileSize (20000000 aka 20MB) defined in my code throws an error as intended and doesn't upload photo_121.tiff - Exceeds max allowed file size Uploading a file (or a total of files) larger than upload_max_filesize (32MB) defined in php settings throws a different error and doesn't upload The uploaded file exceeds the upload_max_filesize directive in php.ini. How to amend this text to be the same as the above? Is this message coming from Apache directly and not PW? Where and how to customize all the notices? Uploading a file (or a total of files) larger than post_max_size (50M) defined in php settings throws no error and doesn't upload 2. file count uploading more files than setMaxFiles (20) defined in PW does upload 20 files. (max_file_uploads in php settings is set to 1000). it lists all the files (how to change that?) and then throws and error: Max file upload limit reached I'd rather have it throw an error and not upload anything at all, how to accomplish that? ___ Here's my contact form code: if($input->post->submit) { if(processContactForm($config, $pages)) { $session->redirect($pages->get("/contact/thanks/")->url); } else { $session->redirect($pages->get("/contact/error/")->url); } here's the function to upload (credits to @ryan) function processContactForm ($config, $pages) { $addedfile = _x('added file', 'contact form'); $input = wire('input'); $sanitizer = wire('sanitizer'); // Set a temporary upload folder where the files are stored during form processing // RC: precede temp dir with a period to ensure it remains non-web accessible $upload_path = $config->paths->assets . "files/temp/"; // RC: create temp path if it isn't there already if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path"); } // New wire upload $user_file = new WireUpload('fileToUpload'); // References name of HTML form field $user_file->setMaxFiles(0); $user_file->setMaxFileSize(20000000); // 20MB $user_file->setOverwrite(false); $user_file->setDestinationPath($upload_path); $user_file->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif', 'pdf', 'tiff', 'zip')); // execute upload and check for errors $files = $user_file->execute(); // RC: use count($files) as your decision whether to proceed not not, rather than getErrors() if(!count($files)) { return false; } // trying to count the number of uploaded files and return false to not upload at all if(count($user_file) > 20) { $user_file->error(_x('too many files!', 'contact form')); return false; } // Save in the ProcessWire page tree; map submission to the template fields $np = new Page(); // create new page object $np->template = "user"; $np->parent = $pages->get("title=userinputs"); $np->status(['hidden']); // RC: for safety, only add user uploaded files to an unpublished page, for later approval // RC: also ensure that using v2.3+, and $config->pagefileSecure=true; in your /site/config.php $np->addStatus(Page::statusUnpublished); if ($input->post->givenname != '') { $np->given_name = $sanitizer->text($input->post->givenname); } else { $np->given_name = 'idle'; } if ($input->post->familyname != '') { $np->family_name = $sanitizer->text($input->post->familyname); } else { $np->family_name = 'idle'; } $np->title = $np->family_name.' '.$np->given_name; // Send all the form's $_POST submissions through ProcessWire's sanitization and/or map to a variable with the same name as the template fields we'll be populating $np->name = $np->title; $np->save(); // Run photo upload foreach($files as $filename) { $pathname = $upload_path . $filename; $np->images->add($pathname); $np->message("$filename"); unlink($pathname); } // save page again $np->save(); return true; } and lastly, here's my success.php template: foreach($notices as $notice) { $class = $notice instanceof NoticeError ? "error" : "message"; echo "<p class='$class'>$notice->text</p>"; } $session->removeNotices(); Thanks for any hints!
-
it doesn't know $page or $pages either…
-
thanks! I wonder though why the ->type-> part is not in the API doc https://processwire.com/api/ref/fieldtype-options/get-options/ because without it, doesn't work