Posted by gazelemone on August 18, 2012 at 12:59am
I am trying to get the logo and menu for my website in a block. That way I can make it disappear on certain pages. I am using Drupal 7 with a theme called "Professional Theme"
Has anyone had any luck with this? Here is what I tried to put in the block with no apparent effect. This is basically the php from the actual page.tpl.php with an added settings reference. I saved it in a block in the php format.
<?php
$settings = theme_get_setting('professional_theme');
<header id="header" role="banner">
<?php if ($logo): ?><div id="logo"><a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>"><img src="<?php print $logo; ?>"/></a></div><?php endif; ?>
<h1 id="site-title"><a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>"><?php print $site_name; ?></a></h1>
<div id="site-description"><?php print $site_slogan; ?></div>
<div class="clear"></div>
<nav id="main-menu" role="navigation">
<a class="nav-toggle" href="#">Navigation</a>
<div class="menu-navigation-container">
<?php
if (module_exists('i18n')) {
$main_menu_tree = i18n_menu_translated_tree(variable_get('menu_main_links_source', 'main-menu'));
} else {
$main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
}
print drupal_render($main_menu_tree);
?>
</div>
<div class="clear"></div>
</nav><!-- end main-menu -->
</header>
?>
Comments
You wouldn't be able to use
You wouldn't be able to use the code from the tpl in a block like that. But, there are easier ways.... if you must have them in blocks, you could turn off the logo and menu from the theme settings then use the system's main menu block and a regular block with an img tag pulling your logo from somewhere. Then you would be able to use the visibility settings with those blocks.
Alternatively, and much easier in my opinion, you could use CSS to hide your menu and logo based on the unique body class that most themes have built in. Usually it's the node id or url alias.
Do either of those sound like it would work for you?
Is there a common denominator
Is there a common denominator for the page you want the menu to appear or to NOT appear on? For example you want to hide your menu on all pages where node is the type 'whatever'...??
First off though, you #1 problem with the code you provided is it is not proper PHP. The php filter expects the text entered to be into the block to be in php language. The tpl files in drupal are html (with a php extension). So you can't just wrap the html code in php brackets.
If you want to trick the php filter into thinking you have entered php you can start your code with
<?php
?>
<?php
?>
However I agree with jeremyr that using a block for this may not be you best option ;)
If you do have a commonality, a solution that may work for you is leaving the menu defined like it is in your page.tpl.php and just add a php if statement to display/hide if this commonality exists.
An example of this might look like..
usecase: authenticated user
<?php global $user;if ($user->uid != 0): ?>
<!-- Include your code here -->
<!-- Optionally use <?php else: ?> here to print something in place of your logo and menu when it is hidden -->
<?php endif; ?>
Another example may look like,
usecase: page url path is equal to
<?php if (stripos($_SERVER['REQUEST_URI'],'/path/') !== false): ?><!-- Again include your logo and menu code here -->
<?php endif; ?>
You could use any if statement that would fit you case but hopefully that helps.
Thanks for the suggestions!
Thanks for the suggestions! This was actually my first post for help, and I am amazed at how fast you responded. I went with the css solution. I just added a change to the path. Works like a charm! Thanks!