Jump to content

froot

Members
  • Posts

    686
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by froot

  1. 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.
  2. 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 _()?
  3. 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.
  4. 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!
  5. 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.
  6. 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!
  7. 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!
  8. 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?
  9. 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!
  10. [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!
  11. 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?
  12. 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!
  13. 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?
  14. 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. &Uuml; 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 &Uuml ? I always and still struggle with this kind of problems. $new_parent = htmlspecialchars($lc->club_region->title); // &Uuml; 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.
  15. but isn't the currently used PW-version CKEditor 4? What about CKeditor 5?
  16. I actually went on with @dynweb's advice and am now working with Repeater-Matrix. That works like a charm! Thanks everyone.
  17. 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?
  18. it's already inside a repeater-field so it would be a repeater field inside a repeater-field :-/
  19. 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?
  20. 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!
  21. it doesn't know $page or $pages either…
  22. 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
  23. namespace ProcessWire; function myfunction() { echo $config->paths->assets; // Notice: Undefined variable: config (…) } can't access the API inside a custom function. Didn't have that problem before. This seems like a basic setting. What could be the reason?
  24. how do I return all the options of an option field? I have an option field on the children pages and need to list them. The API-documentation says as follows… $items = $fieldtypeOptions->getOptions($field); but it doesn't work. Also unclear if $fieldtypeOptions is to be used as is or would that be replaced with my field? It's not apparent if you're not a pro, the API documentation lacks examples or explanations as usual.
  25. It was a stupid typo from my side, I found out using the console. I kinda got it to work or at least use the styles I add to mystyles.js. Now I'm trying to build a uk-accordion using the styles which is not that simple after all, not to mention for the client. I added these three styles: { name: 'uk-accordion', element: 'ul', attributes: { 'uk-accordion': 'collapsible: true' } }, { name: 'uk-acc-title', element: 'a', attributes: { 'class': 'uk-accordion-title' } }, { name: 'uk-acc-content', element: 'div', attributes: { 'class': 'uk-accordion-content' } } Also very important, as you mentioned, you need to first apply the appropriate html tags to the elements you want to add the styles to, otherwise the styles won't appear. So for the <a> element I first need to make it a link with href="#" (not too complicated, I think the client can handle that). For the content no need to add a tag. And for the <ul>, you guessed it, turn it into an unordered list first. Tried that in different orders, but either way, adding the uk-accordion style to the <ul> element always puts the <a> element after or inside the <div> or turns both elements into seprate <li> elements which is not how it should be thus it doesn't work. Can you think of a way to just apply the ul-style to the list and it adds the other styles to its children accordingly? Thanks for your help.
×
×
  • Create New...