Search code examples
phphtmldrupaldrupal-7

How can i create a php conditial statement in drupal 7 page template


I wanted to render different regions on a page.tpl.php file based on the current pages title. The following code:

<?php if ($title == "My Drupal Page"): ?>
        <?php print $title; ?>
<?php endif; ?>

doesnt seem to work for me. i made sure to print the actual $title first and then copy pasted so it compares the correct title but still no results


Solution

  • For whatever reason this worked for me:

    <?php if( drupal_get_path_alias() == "my-drupal-page"): ?>
      <?php print $title; ?>
    <?php endif; ?>
    

    i can only assume that there was extra text i couldn't see associated with $title. drupal_get_path_alias() outputs the url alias and works as expected so far