help with some basics

urbanarpad - July 17, 2008 - 18:18

I have the Pro Module Development book and it's very helpful. I've read much of the docs and they help somewhat though most of the info caters to... "this is how you do this..." and if you happen to want to do that then fine. If you want to do something different, just hope that it's close enough.

Ok, enough whining.

I'm still missing some basic info that I haven't been able to search, Google, glean, grok or find. Can anyone help?

What variables or arguments are available on a page or in a block with PHP? I know about arg(n) but where can I find which global variables would be available. Is there some reference that just lists them? (note: the API page for 5.x has a link to "GLOBALS" but is empty).

Thanks.

As far as globals go there

nevets - July 17, 2008 - 19:39

As far as globals go there is $user (which represents the person currently viewing the site). There may be other general purpose globals but more likely you are looking for this page. Follow the links to each template (ex: page.tpl.php) and it will show you the variables available in that scope (they are not globals).

Well, I didn't think to do

urbanarpad - July 17, 2008 - 20:35

Well, I didn't think to do this (remember, this is IN page content):

global $user;
print "<pre>";
print_r( $user );
print "</pre>";

That helps. Though there have to be more. I thought there was a $nid or $node or something? And what about site info or page info? Isn't there a reference for this somewhere?

I saw the page.tpl.php info on the PHPTemplate pages but none of that works...
I can't go

global $breadcrumb;
print $breadcrumb;

It doesn't work.

I also tried

print variable_get('breadcrumb', '');

Also doesn't work.

I'm just guessing at things here. Do I really have to start reverse engineering code to figure this stuff out? is "The Code is the Documentation" really the Drupal way?

Are you wrapping those

criznach - July 17, 2008 - 22:07

Are you wrapping those examples in php tags? And if you're putting these in page content, is the input filter set to "PHP Code"?

The things you wrote above should work, but in your examples they not in php tags.

This works for me:

<?php
print("<pre>" . print_r($GLOBALS, true) . "</pre>");
?>

And IMHO you're wrong about "The Code is the Documentation". Especially in the Drupal core. Drupal 5 has excellent documentation - if you can't find it you must not have looked very hard. Version 6 is running behind in places, but it's not hard to get access to edit pages if you find them lacking or wrong.

Are you doing theming or are you creating modules? If you're theming, you might have the wrong book. Here are some references for what's available in template files:

See:
http://drupal.org/theme-guide/5
or
http://drupal.org/theme-guide
or
http://drupal.org/node/190815 - for variables available to specific template files.

Thank you. I appreciate

urbanarpad - July 17, 2008 - 23:16

Thank you. I appreciate your help, I say, to make sure you understand that before I disagree with you.

There *is* a lot of documentation for Drupal. IMHO, it's just hard to find anything. And yes, I tried hard. I'm frustrated and I'm tired. I'm about two months into my Drupal "experience" and it's been a struggle the whole time. I finally bought the Pro Dev book last week and that helped *a lot* to explain how things work.

Sure, if you're just trying to do some simple things, there's text there that will lead you through it. But, if you're trying to anything that deviates that doesn't exist in a Tutorial, Howto or Snippet, it becomes a nightmare. Am I trying to theme or develop modules? Dude, anything I can to get by.

Here's are some examples (and I don't expect you to help me on these because I'll figure them out):

I needed a custom search form with extra options. I used hook_form_alter to add the fields I need and have a hook_search to use them but I spent hours trying to figure out how to access those extra fields despite having the book and the documentation. I still haven't figured it out as I think search_form has a validate or submit function that messes it up. Too tired. Put it down for now but I'll be back to reading the code soon.

I went through every single gallery and image module trying to create an image gallery for users. Finally I threw them all out and am back to just using a custom content type, taxonomy and CCK image field. Though, I have to use Views and Views Fusion do display views from three different content types and I think Views Fusion doesn't like image fields. I think I'm just going to theme it by hand in the end.

Ok, you say, those are third party modules, Drupal can't be responsible. True.

I want to have users be able to upload images based on context -- users shouldn't have to figure out which taxonomy to pick, when they want to upload to the, let's say, "Cars" gallery, it should be a hidden field that just works. Trying to figure out how to alter a form isn't that difficult (again the book helped) but coming to the realization that you can only alter a form once... that if I have multiple image galleries with different hidden field requirement I have to build forms from scratch and figuring out how to do THAT? Nightmare.

I like Drupal. It's amazing what it can do with just a little bit of work... when you don't get stuck.

I just wish there was a straightforward reference. api.drupal.org is the closest thing to that but it only helps module development.

You can't show me a page that describes how to figure out what globals can be available IN PAGE, not in page.tpl.php or block.tpl.php. It doesn't exist.

Furthermore, I just tried

print("<pre>" . print_r($GLOBALS, true) . "</pre>");

and it worked. Before,

print "<pre>";
print_r( $GLOBALS );
print "</pre>";

didn't work. Now it does. Aaargh!!

Sorry to vent on you and I DO appreciate the help but, Aaargh!

P.S.
I know, "get involved with documentation." Ok, when I'm caught up with my projects again, I just might.

Welcome to Drupal. Looks

criznach - July 18, 2008 - 04:49

Welcome to Drupal. Looks like your skills are already getting sharper. :)

The variables documented in

nevets - July 18, 2008 - 02:15

The variables documented in the reference are basically local to the appropriate tpl.php file. So something like <?php print $breadcrumb; ?> will work in page.tpl.php (and its derivatives) If you declare it as global though it will not work since that will hide the local $breadcrumb. And of course the variables only work in the the context of the correct tpl.php and do not work elsewhere.

 
 

Drupal is a registered trademark of Dries Buytaert.