Jump to content

Problem with accessing userdefined image-fields


biber
 Share

Recommended Posts

Hi,

in a gallery I have defined some extra fields to my image-field.

As long as I show the overview with all thumbnails I can access to my fields (for exemple field "kopf"). But if I select one image I only get an empty string. Very strange: if I get ('kopf|name_1') it shows the content of the "kopf"-field. ("name_1" is a field at the page without reference to the image)

Here an excerpt from my template:

galerie-ausschnitt-.thumb.jpg.8d8ac97aac2b95aaef83af34fc943630.jpg

Link to comment
Share on other sites

I'm not sure where $images or $seg is defined in your code.
Anyway, you can access images with key inside loops like this:

foreach ($page->images->getValues() as $i => $image) {
	echo "<img class='number_$i' src='$image->url'>";
}

// $page->images is an object
// $page->images->getValues() is an array

You can also access an image without looping

$firstImage = $page->images->eq(0); // first image
$thirdImage = $page->images->eq(2); // third image

 

If name_1 isn't an extra image field, then you should access it via $page->name_1. 
 

Link to comment
Share on other sites

hi @ngrmm,

thanks for your reply.

maybe I have shortened my code-excerpt too much 😉

$seg1 = $sanitizer->pageName($input->urlSegment1);

$images = $page->images;

name_1 defines a sort criteria, not importent in this context.

My problem is:

At the overview with all thumbnails I can access to my user-defined imagefields (for exemple field "kopf"). But if I select one image I only get an empty string.

$images->$seg1->get('kopf|name_1') shows field 'kopf' as expected.

$images->$seg1->get('kopf')  shows an empty string

 

Link to comment
Share on other sites

@biberI don't get what you are doing with the $seg1 variable.
What are you trying to access with $images->$seg1 ?

And I doubt that the pageimage/s Classes have a get method that accepts two fieldnames.

Let's say you want the value of the description field from your third image. You could access it this way:

$images = $page->images;
echo $images->eq(2)->description;



 



 

Link to comment
Share on other sites

I guess you use numbers in you url segments right?
So this would result into $images->2->get('foo|bar')?

Maybe I'm wrong, but I don't think this syntax is correct.

 

Link to comment
Share on other sites

  • 1 month later...

Hi all,

still have problems with that userdefined fields:

to every image I have defined some fields, represented by a number in the database-field "filedata". Here one example:

{"_109":{"data":"ehemalige Post","data1015":""},"_108":"schon lange gibt es hier kein Postamt mehr","_110":"S\u00f6rup Dorf","_111":"","_112":"2024-02-17 00:00:00","_114":""}

_109="kopf", _108="bildtext", _110="iname_1", _ 111="iname_2" and _112="iname_3"

I can access to this content by $images->$seg1->filedata['_xxx'] for all parts but not to _109(kopf), which is a TextLanguage-field and contains two parts. While I do not need the language-function anymore, I tried to convert it to a simple Text-field, but this lead to a long error-list and no success.

Any idea?

Link to comment
Share on other sites

If I set a var_dump($images->$seg1->filedata['_109']);

I get the error

Quote

Warning: Undefined array key "_109" in /var/www/html/processwire/processwire-master/site/templates/galerie.php on line 84

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...