biber Posted March 7 Share Posted March 7 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: Link to comment Share on other sites More sharing options...
ngrmm Posted March 7 Share Posted March 7 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 More sharing options...
biber Posted March 8 Author Share Posted March 8 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 More sharing options...
ngrmm Posted March 8 Share Posted March 8 @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 More sharing options...
biber Posted March 8 Author Share Posted March 8 Hi @ngrmm, with $seg1 I am able to access a single image of my gallery. The method is described here: https://processwire.com/docs/front-end/how-to-use-url-segments/ The crazy thing about my template is, that it works with $images->$seg1->get('kopf|name_1') but not with get('kopf') or $images->$seg1->kopf Link to comment Share on other sites More sharing options...
ngrmm Posted March 8 Share Posted March 8 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 More sharing options...
biber Posted March 8 Author Share Posted March 8 My url segments are the names of the images. This works as desired. You may have a look at the site: http://malabu.de It is an elder version, I'm working at a new edition with a better sorting function. Link to comment Share on other sites More sharing options...
biber Posted April 14 Author Share Posted April 14 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 More sharing options...
netcarver Posted April 14 Share Posted April 14 I don't have any idea - but could you let us know what error(s) you are getting, as that might help? Link to comment Share on other sites More sharing options...
biber Posted April 14 Author Share Posted April 14 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 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