I've been making the node entries have their own containers and i'd like to carry that theme to the admin areas and create content page. The problem is - when a div in node.tpl.php is defined via div and css the same div tag is not placed on the admin, calendar, or the create content stuff. There is only the background that has been placed for the overall container i've specified. I was thinking perhaps there is a *magic* if / else clause i could throw in my page.tpl.php that says, "if it's an admin page, then contain in this class element, elseif it is a node then use this element". I'm not familiar enough with the php calls that i can figure this out.

Anyone have any good tips, workarounds, solutions?

Comments

andremolnar’s picture

<?php if (arg(0) == 'admin'): ?>
<div class="foo" id="bar"> <?php print($something)  ?> </div>
<?php  else: ?>
<div class="foo2" id="bar2"> <?php print($something2)  ?> </div>

That might be the kind of thing you are thinking of doing in page.tpl.php... and it may work - someone please correct me if I'm wrong ;-)

andre

freyquency’s picture

That helps a lot, I haven't tried it yet, because I wouldn't know what to put in as $something. Perhaps I would also need to modify template.php ?

freyquency’s picture

I've been too busy to actually think about what you wrote. For my purposes I didn't need to have any print commands, just the arg at the beginning... thanks! Now I can include a specific div when on the admin screen and a bunch of others...

for example:

<?php if (arg(0) == 'admin' || arg(1) == 'add' || arg(2) == 'edit'): ?>
<div class="admin">
<?php endif; ?>

... stuff

<?php if (arg(0) == 'admin' || arg(1) == 'add' || arg(2) == 'edit'): ?>
</div>
<?php endif; ?>

allows me to provide a background to the admin, create content, and edit content screens, with just one div tag. This is really useful to me because I have entries sort of as their own little boxes, with a background behind them. This background wasn't great to have text against.

for those that are interested the number inside the parenthesis is where it falls in the url, so:

http://yoursite.com/admin is arg(0)
http://yoursite.com/node/1/edit is arg(2)
http://yoursite.com/node/add is arg(1)

EDIT: oops! don't use class="admin" - it's already used. I changed this to class="backend"

freyquency’s picture

Also
arg(0) == user

is another good one to use... It works even if you changed the user profile path with URL alias.

If there's any other places that are difficult to get themed and this works please post them!

freyquency’s picture

arg(0) == product

for the product page in e-commerce.

andremolnar’s picture

And don't feel you are restricted to the page.tpl.php file. It could come in handy by overriding some other theme functions in your custom tpl files or other standard template files.

andre

aftershock’s picture

The above works well, however I had set up 'mysite/careers/vacanices' to point to 'taxonomy/term/13' to display a list of my vacancies. I tried to use arg(1)=='vacancies' to target the vacancies part of the URL. It did not work.

When I printed out the arg(0) I got a result of 'taxonomy', likewise with arg(1) a result of 'term'.

This makes it not as intuitive or as usefull as I first thought.

How could you tagert a specific collection of nodes using mine as an example just targeting all the nodes that were published under the category of vacancies. Can this be done using a modfied node.tpl.php? If so what variables etc can be used?

Thanks

andrew_p’s picture

I have read drupal handbooks about using arg(). And I already test them. Then i realize that i can't use arg() with URL generated by URL alias. Does anyone can solve this problem?

Anonymous’s picture

Interesting alternative using:

$_REQUEST['q'] and explode

http://drupal.org/node/57969
FnL