Jump to content

Recommended Posts

Posted

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.

Posted

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?

Posted

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'
  • Like 2
Posted

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.

  • Like 1
  • 2 years later...
Posted
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…

  • Like 1

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
  • Recently Browsing   0 members

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