Help with line of code

Hi, having a bit of trouble with some code…

<?php echo $user_data['group_id'] == GROUPS_ADMIN ? '<?php echo $post['name'];' : ''; ?>

You can see in that line of code that the name is only to be displayed for the Admin - but the php will not work within the ’ ’

I cannot figure a way to have it so I can write PHP inbetween and only have the admin view it.

Any help or tips would be much appreciated.

Thanks,

Paul



<?php echo $user_data['group_id'] == GROUPS_ADMIN ? $post['name'] : ''; ?>


You already have the echo at the start of the statement, no need to repeat it :slight_smile:

Ah ok - I think that was not the best example … there is also other things to go inside… this is the full HTML I want within the ’ ’ …

<div class="main_box">
  <h4>Address</h4>
	<table border="0" cellpadding="3" cellspacing="1">
		<tr>
			<td>Address Line 1:</td>
			<td><?php echo $user['address_line1']; ?></td>
		</tr>
		<?php if ($user['hide_email'] == 0) { ?>
			<tr>
			  <td>Address Line 2:</td>
			  <td><?php echo $user['address_line2']; ?></td>
	  </tr>
			<tr>
			  <td>City:</td>
			  <td><?php echo $user['city']; ?></td>
	  </tr>
			<tr>
			  <td>County:</td>
			  <td><?php echo $user['county']; ?></td>
	  </tr>
			<tr>
			  <td>Country</td>
			  <td><?php echo $user['country_name']; ?></td>
	  </tr>
			<tr>
			  <td>Postcode:</td>
			  <td><?php echo $user['postcode']; ?></td>
	  </tr>
		<?php } ?>
	</table>
</div>

For a big chunk like that you probably want something like this, like you already have with $user[ ‘hide_email’ ]:


<?php

if ( $user_data[ 'group_id' ] == GROUPS_ADMIN ) {

?>

<div class="main_box">
  <h4>Address</h4>
	<table border="0" cellpadding="3" cellspacing="1">
		<tr>
			<td>Address Line 1:</td>
			<td><?php echo $user['address_line1']; ?></td>
		</tr>
		<?php if ($user['hide_email'] == 0) { ?>
			<tr>
			  <td>Address Line 2:</td>
			  <td><?php echo $user['address_line2']; ?></td>
	  </tr>
			<tr>
			  <td>City:</td>
			  <td><?php echo $user['city']; ?></td>
	  </tr>
			<tr>
			  <td>County:</td>
			  <td><?php echo $user['county']; ?></td>
	  </tr>
			<tr>
			  <td>Country</td>
			  <td><?php echo $user['country_name']; ?></td>
	  </tr>
			<tr>
			  <td>Postcode:</td>
			  <td><?php echo $user['postcode']; ?></td>
	  </tr>
		<?php } ?>
	</table>
</div>

<?php

}
// if

?>

Perfect, thank you - I am a bit of a tool - I sometimes find it hard to spot the simple things ! :slight_smile:

PHP’s alternate syntax can help add clarity in templates. :slight_smile:

Unfortunately it can’t be used for bracket matching though. I prefer the standard syntax with a comment following the closing brace.

I can’t stand that alternate syntax also. The best way to avoid complexity in any template is to do logic intensive things ahead of time. Than feed the result into the template to just be printed with little logic involved.