Jump to content

fruid

Members
  • Content Count

    142
  • Joined

  • Last visited

Community Reputation

10 Good

About fruid

  • Rank
    Sr. Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. OK got it working now, I should always never forget that even though it's just one item, it's still inside an array. thanks
  2. so I have a Profields Table on a sibling's page, trying to access it from its sibling's page (DUH!) which is $page now, cause that's where I am right now. I do $toc = $page->siblings("template=tableofcontents")->tableofcontents_table; $toc->render(); or $toc = $page->siblings("template=tableofcontents"); $toc = $toc->tableofcontents_table; $toc->render(); but it just won't work because Call to a member function render() on null The table clearly is there and clearly is a sibling and its template is as stated and the table also. Please help me quick, about to throw the computer out the window, thank you.
  3. OK I got it working now, a little workaround made it happen it's acceptable… if (count($item->images) > 0) : $output .= '<img src="'.$item->images->first->size(450, 250, $options)->url.'"/>'; else : $defaultID = $fields->images->defaultValuePage; $output .= '<img src="'.$pages->get("id=$defaultID")->images->first->size(450, 250, $options)->url.'"/>'; endif; Also needed to be careful about the if conditions to avoid having ->size() be called on a NULL object. Hope this helps someone in the future… cheers
  4. it's working fine. even got the cropping work now. There's no access problem to the real images, just cannot access the default images. I could save the default images in another folder on root level, crop them without the API etc. but I'm not sure this is the easiest way. Any ideas?
  5. I have a related question I believe. I had a AJAX working fine, the markup of which is pretty much identical to what is initially loaded normally – except for the variables's values of course – and the AJAX loaded content replaces that. The php file that is loaded via AJAX sits in the folder above /site/. Now I started to use default images for the images fields and it doesn't work anymore. Default image, just to clarify, I set by creating a dummy page with the same template with the same image field. This works for the normally loaded content, but the AJAX call seems to fail to call functions like size() on the images: Call to a member function size() on bool When I remove the size()-function, the image is there, just not cropped. And also it fails to access the default value for the image fields. Forbidden You don't have permission to access the/path/to/site/assets/files/1234/ Any ideas?
  6. any more advice here? This is my archnemesis, I can't get it to work, I tried in so many different ways. Also, while we're at it, never sure how to escape with selectors… for example if I predefine selectors as $selector = "(events.name~%=$q, events.location~%=$q)"; $limit = "limit=24"; and I then include that to select with either… $items = $page->find("$selector, $limit"); $items = $page->find("$selector", "$limit"); $items = $page->find('$selector, $limit'); $items = $page->find('$selector', '$limit'); $items = $page->find($selector, $limit); or should I do… $selector = "events.name~%=$q, events.location~%=$q"; $limit = "limit=24"; and then either… $items = $page->find("($selector), $limit"); $items = $page->find("($selector)", "$limit"); $items = $page->find('($selector), $limit'); $items = $page->find('($selector)', '$limit'); $items = $page->find(($selector), $limit); what about without variables… $items = $page->find("events.name^=a, $limit"); $items = $page->find("events.name^=a", "$limit"); $items = $page->find('events.name^=a, $limit'); $items = $page->find('events.name^=a', '$limit'); $items = $page->find('events.name^=a', $limit);
  7. why shouldn't I overwrite the title? If I shouldn't and consequently won't, then there's no need for any mentioned work-around-solutions after all. Using the full title (i.e. parents-title/page-title) for the products and the actual title (here short title) for breadcrumbs and admin backend is what I need. Composing the breadcrumbs on the _main.php won't work for me. I was able to accomplish what I need by including _breadcrumbs.php on _init.php. On _breadcrumbs.php I compose the breadcrumb-markup making use of the ->shorttitle and ->fulltitle hooks I created on _init.php, and store this markup in a $breadcrumbs variable. On _main.php I output this variable and done. However, now I'm in doubt again because… What's the concern? It seems to work fine…
  8. 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!
  9. 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!
  10. 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.
  11. 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.
  12. 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 _()?
  13. 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.
  14. 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!
  15. 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.
×
×
  • Create New...