Community & Support

Problems using arg() and $node->nid

I am trying to change where the add story form shows up. Right now I have the preview on the left side of the screen with the titles of the recent articles on the right. If I click on one of those stories it removes those two elements to make one big box to view the article.

Basically how I want it is the only thing that is to show in the two column view is the recent articles and the preview. Everything else should be in the 1 column box.

I have the regular articles working, but the admin section, add story, account information - all shows up in the preview panel. I guess the easiest way to describe my question.

When you first visit the drupal site you get the listing of articles with the preview. What I want is an if statement that will check to see if a story has been opened, or if we are viewing say the admin section...or adding a story...and if so open it in the 1 column div.

I thought I had the solution with:

[code]

<?php

   
if(!isset($node)) {
       echo
"<div id=\"content_container\">";
    } else {
       echo
"<div id=\"content_container_full\">";
    }
?>

[/code]

But alas it does not work the way it should :( Please help!

Comments

<?php if (arg(0) == 'node' &&

<?php
if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'story'):
?>
would do the trick for the node submission form.

To see if you’re somewhere in the admin area:

<?php
if (arg(0) == 'admin'):
?>

[code]

[code]

<?php

if(!isset($node)) {//if (!$node->nid) {
 
echo "<div id=\"content_container\">";
} elseif(
arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'story') {
  echo
"<div id=\"content_container_full\">";
} else {
  echo
"<div id=\"content_container_full\">";
}
?>

[/code]

I added the check for add story as an elseif for testing. Unfortunately neither of the above worked :( Is arg() part of drupal or do I have to build that?

Thanks for the help!

arg() is indeed part of

arg() is indeed part of Drupal. (API)

Maybe this works:

<?php
if ($node->type == 'story' || (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'story')) {
  echo
'<div id="content_container">';
} else {
  echo
'<div id="content_container_full">';
}
?>

The above snippet uses content_container on pages with a story node and on the story submission form. All other pages get content_container_full. Or should it be the other way around? A bit confused about what you’re exactly trying to do :)

Ya my pseudocode went and hid

Ya my pseudocode went and hid under the table....the client is changing their mind faster than I can update it lol. You were close. Now I have to think carefully on my wording lol

The default drupal page shows the 'preview' of the articles. I am still doing this, but only the most recent article is shown as a preview when you first load the page (please fill in terminology where it needs to be) and 6 other article titles show up on the right. Any article title that is clicked on will open the article in the content_container_full - which removes the article titles so that the article can be viewed in its full context.

Basically I want the full node to show up in the content_container_full and the preview node to show up in content_container. Anything to do with the configuration of Drupal needs to show up in content_container_full (admin, add story, etc).

That would take care of the biggest issue that I have - the other I will work out after this. I didn't count on taxonomy to mess up some of my template settings. :(

...

Isnt this just a matter of block visibility?

IE:

Dont show the blocks in the offending region on these pages:

admin
admin/*
node/add/*
node/*/edit

Assuming you have built a layout with collapsible columns.

Alternatively, instead of ramming that logic into page.tpl.php use similar logic to set a class in a variable in function themeNAME_preprocess_page.

Hi jmburnz, Ya I didn't use

Hi jmburnz,

Ya I didn't use collapsible columns with this template. Different types of views result in the layout of the site changing - pain in my arse, but the client wants it :P

Thank you for your suggestion on the function. I normally would do something like that but I am trying to get the feel for theming in Drupal. When I tidy up my logic I will definitely be using functions.

Thanks again!

I had to come back to this...

I still did not work out determining if I was creating an article.

If I clicked to edit the article, it opened in content_container_full. If I clicked on create, it puts the create article into content_container instead of content_container_full.

<?php
if ($node->type == 'story' || (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'story')) {//if(!isset($node) || $_GET['q'] == 'taxonomy') {//if (!$node->nid) {
        
echo "<div id=\"content_container_full\">";
        
         } else {
         echo
"<div id=\"content_container\">";
         }
?>

I have included the code that selects what view I should be using. Everything after // is what I have tried previously. I don't understand why the arg() is not working when I see what is in the address bar of the browser: ?q=node/add/story. What would stop the arg() check from working?

Thanks!

Ok, simplified the IF

Ok, simplified the if statement to this:

iif (!$node->nid && arg(0)=='node' || !arg(0)=='admin' && !arg(1)=='add' && !arg(2)=='story' ) { ?>

That makes everything almost work - except now when I try to create an article it shows it in the small preview window rather than opening it to a full screen.

What am I missing in that if statement to differentiate /node/add/story??

Everything else seems to work, except the create article page.

Flipped around how I was

Flipped around how I was looking at it - works now ;)