2

I save image files from within my plugin through assets->insertFileByLocalPath(). Unfortunately, i can't give the image title as paramter to the method.

What is the easiest way to change the image title after insert, espacially considering different languages?

UPDATE

Ok, i found a solution (moved to the answer), but how do i save values for different languages?

  • 1
    You should post that as an answer! To select a specific locale you would add $criteria.locale = "en-us". Although you may want to save it without locale first so that it copies the titles to all locales by default; and then retrieve the specific locale using the above, overwrite the title, and save again. – Douglas McDonald Apr 2 '15 at 22:33
  • you're right, i will post an answer. Thanks for the hint with the locale criteria! – phaetons Apr 3 '15 at 19:22
1

Here's how i solved it:

$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->id = $assetId;
$elements = $criteria->find();
$element[0]->getContent()->title = 'New Title';
craft()->elements->saveElement($element[0]);
|improve this answer|||||
  • Can you check this answer as best answer? – dralshehri Jan 12 '16 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.