KarlvonKarton Posted September 18, 2016 Share Posted September 18, 2016 Hi all, I could not find the answer to following question. How can I add multilingual descriptions to images or files with the API? $p = $pages->get(1234); $p->of(true); $p->images->add("http://www.somewhere.com/files/filename.jpg"); $p->save(); $p->of(false); I've been reading the link below, but can not figure it out in the above code... https://github.com/ryancramerdesign/ProcessWire/issues/496 ps: $images or $files are "Array of Items" in my case Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 18, 2016 Share Posted September 18, 2016 https://processwire.com/api/ref/pagefile/description/ 1 Link to comment Share on other sites More sharing options...
KarlvonKarton Posted September 18, 2016 Author Share Posted September 18, 2016 It is the reference to the just added file what I'm struggling with. When I did: $p->images->add("http://www.somewhere.com/files/filename.jpg"); then how to reference (example) $images->last_added_image_file... (or something like that) Link to comment Share on other sites More sharing options...
adrian Posted September 18, 2016 Share Posted September 18, 2016 $p->images->last() 1 Link to comment Share on other sites More sharing options...
KarlvonKarton Posted September 18, 2016 Author Share Posted September 18, 2016 3 minutes ago, adrian said: $p->images->last() Thus? // get page // ... $en = $languages->get("en"); $fr = $languages->get("fr"); $p->images->add("http://www.somewhere.com/files/filename.jpg"); $lastimage = $p->images->last(); $lastimage->set("description$en", "Description in English"); $lastimage->set("description$fr", "Déscription en Français"); // ... // save Link to comment Share on other sites More sharing options...
horst Posted September 18, 2016 Share Posted September 18, 2016 Don't really know, but if your above code doesn't work, you also may try with a $p->save(); after add() and before getting the $lastimage. 1 Link to comment Share on other sites More sharing options...
KarlvonKarton Posted September 18, 2016 Author Share Posted September 18, 2016 FYI I got it to work like so: // ... $p->files->add('http://www.somedomain.pw/files/somefile.pdf'); $lastfile = $p->files->last(); $p->of(false); // not sure about this $lastfile->set("description$en", $name); $p->save(); ps: save() can be after last() 1 Link to comment Share on other sites More sharing options...
szabesz Posted September 19, 2016 Share Posted September 19, 2016 8 hours ago, KarlvonKarton said: $p->of(false); // not sure about this When you are not sure about this, you might want to: $of = $page->of(); and later on $page->of($of); like this: $of = $page->of(); $page->of(false); $page->set('property', 'value'); $page->save('property'); $page->of($of); source: https://processwire.com/blog/posts/processwire-2.6.9-core-updates-and-new-procache-version/#processwire-core-updates-for-2.6.9 BTW: you might want to give $page->setAndSave()a shot. 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now