I need to add a token that displays the current page number on the title when viewing nodes that are paginated via smart_paging.

It's not possible to use the token current-page:page-number provided by tokens module.

We need a token that will reflect the paged node.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcelovani’s picture

Status: Active » Needs review
FileSize
1.64 KB

I have created a patch that adds support for tokens, also created a token for page-number, not to be confused with the one from tokens module.

Tokens module's page-number uses the first argument of a pager i.e. /node/1/page/1/0
Smart paging's token will use the second argument i.e. /node/1/page/0/1

marcelovani’s picture

The previous patch caused errors when I tried to apply. I have cleaned up and here it is again.

marcelovani’s picture

Oops, previous patch failed too
Trying again.

arpeggio’s picture

Status: Needs review » Needs work

Hi marcelovani, thank you for sharing the patch. However, there's an error when trying to apply the patch:

token-page-number-smart-paging-1776804_3.patch:9: trailing whitespace.
files[] = smart_paging.tokens.inc
fatal: corrupt patch at line 12

marcelovani’s picture

Status: Needs work » Needs review
marcelovani’s picture

Hi arpeggio

Can you please try the patch #2 http://drupal.org/files/token-page-number-smart-paging-1776804_0.patch

Patch #2 should work, but I was getting errors because of '\ No newline at end of file' (we use drush make, not git apply)
Then I inserted a line break and issued the patch on #3 which works for me.

So my guess is if you use git apply with patch #2 it should work.

Let me know.
if not, and I can make two separate patch files for the .info file and the tokens file respectively.

arpeggio’s picture

Status: Needs review » Fixed

Hi marcelovani,

I have tested the support for Token and already committed/pushed your patch. Thank you for sharing the patch. Please use the dev version.

BTW, for reference. I tested the support for token using the following code as content of the node body (with PHP code as Text format):

Token page #: <?php print_r(token_replace('[smart-paging:page-number]')); ?>
<!--pagebreak-->
Token page #: <?php print_r(token_replace('[smart-paging:page-number]')); ?>
<!--pagebreak-->
Token page #: <?php print_r(token_replace('[smart-paging:page-number]')); ?>
marcelovani’s picture

@arpeggio Thanks for implementing the code. We use the token on the page title, with metatag module.
This token is useful for paginated nodes while for paginated views we use [current-page:page-number]

In our case the content will be

Lorem ipsum dolor sit amet, in fusce ut pellentesque, libero libero suspendisse orci, ut ante, diam consectetuer rerum sollicitudin. Sed sit et justo dui eget turpis, neque vitae sem mus vivamus sodales quis. Aenean id a tempor massa vitae.

Aliquet maecenas maecenas neque laoreet, odio mi ullamcorper, nulla lacus dolor. Mi netus ligula torquent, id ligula amet sed nec a, nulla wisi ipsum mollis dui vel, interdum nunc nullam turpis eu pellentesque libero.

In the metatag configuration for title: [node:title] | [smart-paging:page-number] | [site:name]

Automatically closed -- issue fixed for 2 weeks with no activity.

welly’s picture

Issue summary: View changes

The big problem with this solution is the token will show even if a page doesn't use smart paging. Is there a way of recognising if smart paging is applied to a particular page?