2

I like to have the same result in a template if the user is logged-in or is on the front page.

So if the user is not logged-in nor on the front page, it should be the same result as if the user is logged in and not on the front page.

I got

<?php if ($logged_in): ?>

Do something

  <?php else: ?>

Do Something Other

<?php endif; ?>

How to extend this to force drupal to do the same on front as for the logged in user if the user is not logged in but viewing the front page

In other words how to get if drupal_is_ _on_front OR $logged_in

elseif

I am a php newbee

thank you for an explanation

closed as off-topic by kiamlaluno Aug 5 '16 at 4:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.

  • This is a plain PHP question: You are asking how to use an if() to check the values returned from two different functions. Drupal doesn't change the PHP syntax, and our task is not teaching PHP. – kiamlaluno Aug 5 '16 at 4:46
1

You would do something like

<?php if (user_is_logged_in() || drupal_is_front_page()): ?>
  Do something
<?php endif;?>

Source:

1

I think you will want the following:

<?php if ($logged_in || $is_front_page): ?>
    Do something
<?php endif;?>
  • it seems I do not understnad the syntax correctly. So if there are two functions like (user_is_logged_in and drupal_is_front_page How does the line look? Like this? <?php if (user_is_logged_in(): || drupal_is_front_page():) ?> – Josh Aug 4 '16 at 18:39
  • Have a look at PHP's manual about Alternative syntax for control structures – mchar Aug 4 '16 at 19:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.