Jump to content

$image-description is null but $image-description1012 not


Andreas Augustin
 Share

Recommended Posts

Hello!

I'm struggling with some strange problem. I want to get the description of an image in my template but it is null.
When I'm dumping the image I see that the value is in a field called description1012. Why?

object(Image)#396 (2) {
  ["changes"]=>
  array(1) {
    [0]=>
    string(9) "formatted"
  }
  ["data"]=>
  array(8) {
    ["basename"]=>
    string(23) "nbr1052-previewbild.jpg"
    ["description1012"]=>
    string(0) ""
    ["tags"]=>
    string(0) ""
    ["formatted"]=>
    bool(true)
    ["modified"]=>
    int(1490190603)
    ["created"]=>
    int(1490190603)
    ["description"]=>
    NULL
    ["url"]=>
    string(72) "http://s7w2p3.scene7.com/is/image/bluetomato/ugc/nbr1052-previewbild.tif"
  }
}

 

Link to comment
Share on other sites

Are you building a multi-language website? 

When saving multi-language fields, PW appends language id to fields. 1012 is the language id for a language installed in PW. You can use $pages->get(1012)->title to see which.

To set description for an image you should first set field to accept descriptions. Go to Fields > image_field > Input > Number of rows for description field.

desc.png.a4916cea7d1c90cf5630647c8d26df2a.png

Then enter a description for your image

field.png.c0eb0e29606188e9163a018dac0b67a3.png

When you save the page, you should be able to get image description using $image->description().

From the core documentation: 

// $image = $page->image_field->first


/**
 * Get or set the file’s description (with multi-language support). 
 * 
 * When not in a multi-language environment, you can still use this method but we recommend using the simpler method of just
 * getting/seting the `Pagefile::$description` property directly instead. 
 * 
 * ~~~~~
 * // Get a Pagefile to work with
 * $pagefile = $page->files->first();
 * 
 * // Setting description
 * $pagefile->description('en', 'Setting English description');
 * $pagefile->description('de', 'Setting German description');
 * 
 * // Getting description for current language (whatever it happens to be)
 * echo $pagefile->description();
 * 
 * // Getting description for language "de"
 * echo $pagefile->description('de');
 * ~~~~~
 * 
 * #pw-group-common
 * #pw-group-manipulation
 * 
 * @param null|bool|Language|array
 * - To GET in current user language: Omit arguments or specify null.
 * - To GET in another language: Specify a Language name, id or object.
 * - To GET in all languages as a JSON string: Specify boolean true (if LanguageSupport not installed, regular string returned).
 * - To GET in all languages as an array indexed by language name: Specify boolean true for both arguments.
 * - To SET for a language: Specify a language name, id or object, plus the $value as the 2nd argument.
 * - To SET in all languages as a JSON string: Specify boolean true, plus the JSON string $value as the 2nd argument (internal use only).
 * - To SET in all languages as an array: Specify the array here, indexed by language ID or name, and omit 2nd argument. 
 * @param null|string $value Specify only when you are setting (single language) rather than getting a value.
 * @return string
 *
 */

public function description($language = null, $value = null) { /* ... */ }

 

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...