I am trying to create a node type that outputs a multi-page article. I have created title and text fields for each page, but how would I split the output of those fields in separate pages?

In the node type there would be fields that have to appear on every page and fields that only have to appear on the first page.

Maybe I'm wanting too much out of Drupal, but it has amazed me several times before, so hey why not this time. :)

Comments

nevets’s picture

First of you may want to look at the paging module. If that is not what you have in mind, If you have written a module, you can achieve what you want in the view hook, if you used CCK you will need to do it in the template. Not knowing how you have organized your content I can only given you general pointers. Part of achieving your goal will be navigation aids above and/or below the content so users can move through the pages. As an example, lets say you have created an instance of this content and it node id is 12. From page 1 you can only move foward so lets say the forward link is node/12&page=2, on page 2 (given there is a page 3) would have a backlink of node/12&page=1 and a forward link of node/12&page=3.

The view hook or template would then need to determine the page it is on, something like this

if ( isset($_GET['page']) ) {
  $page = $_GET['page'];
  // You might want to range check page and
  // if out of range force it back in
}
else {
  $page = 1;
}

Then in general terms the whole code for view the content would look something like

if ( isset($_GET['page']) ) {
  $page = $_GET['page'];
}
else {
  $page = 1;
}
$max_page = ??;  // You need to determine this based on your content

// Output fields common to all pages

// Use $page to determine the page specific part(s)

// Here we put the navigation at the end, it could be in it's own theme function
if ( $page > 1 ) {
  $prev_link = l(t('Previous page'), "node/$node->nid", array(), 'page=' . ($page-1));
}
if ( $page < $max_page ) {
  $next_link = l(t('Next page'), "node/$node->nid", array(), 'page=' . ($page+1));
}
// Print the prev/next links with html approriate to your needs.
dries arnolds’s picture

Wow, this is really helpful. However, I'm thinking this could be done much easier using content templates. I'm using a custom node type and it has a custom template. I installed the paging module and was trying to use that function in the custom template. But (off course?) I can't just use <!--pagebreak-->. Is there an easy command I can use in the templates?

nevets’s picture

Your challange is you want some information to repeat across the variious pages while some of the information varies. The paging mechnisms I am aware of for Drupal break one large "thing" into multiple pages and do not repeat common information. You can think of this part of the snippet


// Output fields common to all pages

// Use $page to determine the page specific part(s)

as the part you might normally place in you content template. The difference is $page is used to determine the part that varies between pages. The top part determines the current page and page count, the buttom part produces the navigation links. Given you unique need I can not think of a simpler solution. On the other hand if you are using Drupal 5 and you can could use AJAX and page just the variable part.

dries arnolds’s picture

The only thing I need right now is how to define a page break in a (contemplate) template. I'm relatively new to Drupal, so maybe it's really simple. Just pasting <!--pagebreak--> doesn't work in templates, and from the code of the paging module I can't find the right command. I'm also relatively new to php. ;-)