Thomas108 Posted July 13, 2014 Share Posted July 13, 2014 Dear processwire folks, i am trying to output the description of a file field within a repeater, but despite extensive forum search I can't find the right syntax. Here is one of my approaches: <?php foreach($page->mp3_repeater as $mp3) { echo "<li><a href='#' data-src='/processwire/site/templates/audio/$mp3->mp3_url'>$mp3->$file->description</a></li>"; } ?> Thanks for your help. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 13, 2014 Share Posted July 13, 2014 $mp3->$file->description should be $mp3->description Link to comment Share on other sites More sharing options...
Thomas108 Posted July 13, 2014 Author Share Posted July 13, 2014 Hhm, I tried that already before and now again. Doesn't work for me somehow. The output remains empty. (On my page of course I entered a description in the file description field.) <?php foreach($page->mp3_repeater as $mp3) { echo "<li><a href='#' data-src='/processwire/site/templates/audio/$mp3->mp3_url'>$mp3->description</a></li>"; } // results in <a href="#" data-src="/processwire/site/templates/audio/song-1.mp3"> </a> ?> Any other idea what could be wrong? Link to comment Share on other sites More sharing options...
kongondo Posted July 13, 2014 Share Posted July 13, 2014 Let's break this down The name of the repeater: mp3_repeater Having iterated the repeater (foreach), each single repeater instance is assigned the variable: $mp3 $mp3 contains various fields one of which is a file field called: file The field file has its own 'internal' fields such as name, description, etc... Putting this together... $mp3->file->description ...should work. You had a typo in your syntax ($file). Btw, why are you using this? data-src='/processwire/site/templates/audio/$mp3->mp3_url' This should work... data-src='$mp3->file->url' 2 Link to comment Share on other sites More sharing options...
adrian Posted July 14, 2014 Share Posted July 14, 2014 kongondo's approach looks to be right to me, but remember that if your file field can handle more than one file, you'll need to specify which file, eg: $mp3->file->first->description or instead of first you can use: last, or eq(n) Or you could set the file field max files to "1" in the field's config settings. 1 Link to comment Share on other sites More sharing options...
lenoir Posted November 15, 2016 Share Posted November 15, 2016 On 15/07/2014 at 1:07 AM, adrian said: kongondo's approach looks to be right to me, but remember that if your file field can handle more than one file, you'll need to specify which file, eg: $mp3->file->first->description or instead of first you can use: last, or eq(n) Or you could set the file field max files to "1" in the field's config settings. Thanks Adrian! I don't know if you've solved Thomas' problem, but you hinted on mine ;-) Stupid mistake… 1 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