Jump to content

Getting field name in the loop


chuguruk
 Share

Recommended Posts

Hi there,

I have no clue how to resolve this problem:

  1. There is list of pages with users
  2. There is list of pages with devices
  3. In device template i have field "page" to select proper user
  4. In front end I have table where I'm looping through devices displaying title and user id.

Problem: I can't display user name.

  • <?=$device->user?>
     is displaying id of user (1114)
  • <?php $user_name = $pages->get(1114); echo $user_name; ?>
     is displaying name correctly (not loop)
  • <?php $user_name = $pages->get($device->user); echo $user_name; ?>
     - not working

How to display user name?

Link to comment
Share on other sites

If 'user' is the name of your page field that holds the users, try

<?=$device->user->name?>
or
<?=$device->user->title?> // if you have a title field in the user template

This works only if the user page field is set to hold only one page.

  • Like 2
Link to comment
Share on other sites

If 'user' is the name of your page field that holds the users, try

<?=$device->user->name?>
or
<?=$device->user->title?> // if you have a title field in the user template

This works only if the user page field is set to hold only one page.

Yeah, already tried that. Doesn't work.

This is my simplified code:

<?php
$source = $pages->get("/programs/"); 
$programs = $source->children();

foreach($programs as $program) {?>
				
<tr class="gradeX">
<td><?=$program->title?></td>
<td><?=$program->computer?></td> //shows page id
<td><?=$program->computer->title?></td> //doesn't show antything
<td class="center">4</td>
</tr>

<?}?>

"computer" is a page select field in program template connected to computer page.

I can:

  • show computer page id
  • manualy put that id in $computer = pages->get(2893);  and echo it's title <?=$computer->title?>

I can't:

  • make that automatic

It should be working:

<?=$program->computer->title?> 

but it doesn't show anything.

Any ideas?

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...