User login

Ask Agaric: Making the book block link to the parent of a book node

bjornkri: Hello, I'm having a bit of trouble getting my head around overriding blocks. I'm trying to make the book-block title a link to the root of the book. I've a lot of questions about how to do that in fact, but to start with I'm not sure how to override it without changing the source... Anyone willing and able to send me in the right direction?
[10:35am] bjornkri: I tried making a block-book.tpl.php, but I'm not sure how to access the link to the root of the book from there, or if that's even possible

[10:37am] ben-agaric: bjornkri: to see what you can theme, add this to your custom block .tpl.php: <?php
 print "<pre>"; print_r(array_values($form));print "</pre>";
?>

[NOTE: Above doesn't work well and is only for forms anyway]

[10:39am] bjornkri: ben-agaric: hmm, this gave me: warning: array_values() [function.array-values]: The argument should be an array..... etc.
[10:40am] ben-agaric: ah, that's right, i need to comment at the original source -- http://mydrupalblog.lhmdesign.com/drupal-form-theming-quick-tip
[10:40am] ben-agaric: Here's the version I use, that actually works!
[10:40am] ben-agaric: <?php
[10:40am] ben-agaric: print '<pre>';
[10:40am] ben-agaric: print_r(get_defined_vars());
[10:40am] ben-agaric: print '</pre>';
[10:40am] ben-agaric:
?>

[10:41am] worldcoast joined the chat room.
[10:41am] fago joined the chat room.
[10:41am] worldcoast: http://nicedit.com/
[10:41am] worldcoast: anyone wanna put this into a module
[10:41am] bjornkri: ah, that did beautifully
[10:41am] bjornkri: thanks, should keep me busy at least for a while
[10:41am] ben-agaric: (er, that's why I didn't use my version, it's split up onto multiple lines and IRC doesn't like that). Glad it worked, is there a link array there
[10:42am] Airer-girl: http://nicedit.com/ IS REALLY AWESOME
[10:42am] Airer-girl: is really awesome* oops caps
[10:42am] marcrobinsone: nicedit?
[10:42am] marcrobinsone: I think there is a module for that already
[10:43am] nikkiana joined the chat room.
[10:44am] bjornkri: ben-agaric: yeah, but nothing I can really use The link array is [content], which are the sub pages of the book, but nothing linking to the root.
[10:44am] bjornkri: All I get is [subject], which tells me the title of the book.

[10:45am] ben-agaric: bjornkri: this is to show on a node/123 page, right?
[10:46am] bjornkri: ben-agaric: yeah, something like that

[10:46am] marcrobinsone: Druplicon: nicedit is http://drupal.org/project/nicedit

[10:46am] bjornkri: actually rewritten to a slug, so /my-precious-content/, but node/123 whatever should do just as well

[10:47am] bjornkri: .. and come to think of it, I guess I could process the current url to strip off anything that's added, since the subpages will be at /my-precious-content/subpage/subpage, and they need to point to the root
[10:47am] bjornkri: seems a bit hackish, but should work
[10:48am] ben-agaric: bjornkri: Drupal knows where it really is, so the best way to do it is based on node id
[10:49am] ben-agaric: disclaimer for this method: this is putting stuff in the theme layer that shouldn't be (separation of data from theming), but what the hey
[10:49am] ben-agaric: $node = node_load(arg(1));

[10:51am] ben-agaric: and then do your print all variables or print the node array to see what you have-- the book parent node ID has to be in there somewhere! Or else look at http://api.drupal.org/ or in book.module itself to see if there is a function for getting book parent from node ID, I'm sure there is
[10:51am] bjornkri: sweet!
[10:51am] bjornkri: yeah, there is indeed a parent
[10:51am] bjornkri: thanks alot
[10:52am] ben-agaric: and you know how to use the l() function to make a link that will have the path alias and all?

[10:53am] bjornkri: I do now

Resolution

Comments

I found this information

I found this information very helpful. Thanks for posting it.

child behavior problems

More BLOG SPAM in the above post -- aaaarg!

These guys aggravate the heck out of me.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.