I'm in the early stages of moving my sites from Drupal 6 to Drupal 7, and I've just discovered that Content Template (which was a CCK module in D5 and D6) is no longer supported in D7. This is proving enormously vexing because my sites depended on it heavily in order to customize nodes.

So I'm wondering how I can re-create the things I've done with tools that still exist.

Here's a perfect example...

Over on unexploredhorizons.net I'm using the Drupal book module to organize and display all novel updates... but the book module is a little lacking in some functionality. Because I'm using it to display multiple works of fiction, and each work of fiction has other associated content, I want to be able to include a novel-specific menu bar at the top of each page. I also want the next/previous page links to display at the top and bottom of each entry (in the standard module it only displays at the bottom).

These are pretty trivial to do with Content Templates. I was essentially able to hand-code each menu link in content templates and surround them with tags that only showed up when you were viewing a specific taxonomy--in other words, the content wouldn't display unless you were viewing the right novel. And I was able to use Content Templates to break out the entire dump of the book entry into sections, isolate the section that created the previous/next links, and copy/paste it to the top of the page as well. You can see an example of what I'm talking about here:

https://www.unexploredhorizons.net/novel/points-between/points-between-c...

It's organized like this:

- Book Chapter Title
- metadata

- Custom Menu (added with content template)
- Graphic

- Navigation link (added with content template)

- Content

- Navigation link (original, part of book module)

How can I re-create this functionality and integrate it into the book module?

Comments

nevets’s picture

You can do that with either the Display Suite or Panels module.

ubersoft’s picture

I will try both. Thanks again!

ubersoft’s picture

... Display Suite and Panels will do some of the things I need, but not all of them. So here's an example.

I know that in Content Templates, if I insert this code into the template for my "webcomic" content type:

<?php print $node->content['custom_pager_top'][1]['#value'] ?>

That it will display a custom pagers "link bar" for Help Desk (one of my webcomics) at the top of the node, but only in nodes within that content type that are flagged with the help desk taxonomy (that's the "[1]").

I know it will do this because Content Templates actually exposes all the different fields that are available for a Content Type, and after a little trial and error I was able to make it work.

Using Display Suite and Panels I can actually add that php snippet into the content type layout, but it doesn't work. It could be that Custom Pagers had changed the variables you're supposed to use, or it could be that D7 no longer supports modifying content type with php code in that way (i.e., I have to move it all to templates. Which will be fun). But there's no way that I can see to even check.

Likewise, using my original example in my first post (getting the book navigation links to appear on the top and bottom of the page), this is what I've done with Content Templates:

<?php if ($node->book['depth']==1): ?>

<div class="NovelBody">
<?php print $node->content['body']['#value'] ?>
<?php print $node->content['book_navigation']['#value'] ?>
</div>

<?php endif; ?>

<?php if ($node->book['depth']!=1): ?>

<div class="NovelBody">
<?php print $node->content['book_navigation']['#value'] ?>
<p><?php print $node->field_chimage[0]['view'] ?></p>
<div class="chteaser"><?php print $node->field_callout[0]['view'] ?></div>
<?php print $node->content['body']['#value'] ?>
<?php print $node->content['book_navigation']['#value'] ?>
</div>

<?php endif; ?>

Which does this:

- checks to see if the index page is displaying (that's the book depth equals 1 part). If it is, it only displays the bottom link (formatting and styling was simpler that way)

- if the index page is not displaying (that's the book depth != 1 part) then it displays the book navigation links, the image for the chapter, the chapter lead, the body of the chapter, and then the book navigation links again.

... I haven't been able to figure out how to make this work. I noticed that Display Suite contains a section where you can store code snippets, but it doesn't seem to make those available anywhere in panels, which gives you the most granular control over the page... and unfortunately the DS documentation assumes a lot more knowledge about the inner workings of Drupal than I have (and it seems to largely focus on Drupal 6).

So anyway. I'm still thrashing around. DS and Panels have taken me about 30% of the way to where I need to be, but I've got a ways to go yet.

nevets’s picture

I would use either Display Suite or Panels (not both).

Display Suite allows for custom fields which can use PHP and has access to the node ($content if I remember correctly, the comment below the textarea notes this).

Panels allows for custom content which can also contain PHP

ubersoft’s picture

I guess I'm a little confused now, because it looks like they're integrated -- Display Suite for D7 has a feature that lets you use the panels editor to modify how everything lays out in a node, and that gives you more granular access to all the parts of the node than the standard view does.

So for example, if I go here:

admin/structure/ds/layout

I see a list of all the content types I can modify. So if, from there, I click "webcomic" (my content type for my webcomics) I get taken here:

admin/structure/types/manage/webcomic/display

Which is the standard page for modifying that content type. There aren't any tools I can access from there that let me add any DS-specific functionality.

Is there any DS documentation other than the link posted on the DS site? That documentation contains links to external sites that no longer exist.

nevets’s picture

If you visit Administration » Structure » Display suite there are some options there including one called fields where you can add various field types.

ubersoft’s picture

... but they don't show up anywhere.

I'm convinced I'm doing this wrong, but I can't find any documentation that shows me how to do it right. But here's what I'm doing...

1. Go to admin/structure/ds/fields
2. Click the "add a code field" link
3. Put in a human-readible label in the Label field, check the "node" checkbox, paste the relevant php code in the Field Code field. I leave the Text format set to its default, "Display Suite code"
4. There is an extra option for "tokens" where you can replace elements in the field with token placeholders. I've played with it with some code snippets I've added, and I've left other code snippets alone.
5. I click "Save". I'm taken back to admin/structure/ds/fields. The field is added to the table on this page, with the option to either edit or delete it.

At this point, I don't know what to do next. When I go to edit a node structure, I can't find those fields anywhere, and I can't actually add them to the content node layout in any way. Apparently adding the fields isn't enough--either the feature is broken or there's an extra step necessary to bridge the gap between creating a field and adding it to a node that I haven't figured out yet.

I really appreciate your advice, and I don't mean to be thick about this, but I can't find any documentation on the drupal site that covers this. If it's there, I don't know what I'm looking for or simply don't understand it when I look at it.

nevets’s picture

If you go to the "Manage Display" tab for the content type, the custom field should now be in the list of fields you can display.

ubersoft’s picture

... I didn't realize I had to select a layout before any of the custom fields would display. Now I know, and all the fields are showing up. :)

Thanks for your help. Now I just need to figure out how to convert my d6 custom php to d7 custom php...