Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#3 | token-page-number-smart-paging-1776804_3.patch | 1.55 KB | marcelovani |
#2 | token-page-number-smart-paging-1776804.patch | 1.64 KB | marcelovani |
#1 | token-page-number-smart-paging-1776804.patch | 1.64 KB | marcelovani |
Comments
Comment #1
marcelovaniI 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
Comment #2
marcelovaniThe previous patch caused errors when I tried to apply. I have cleaned up and here it is again.
Comment #3
marcelovaniOops, previous patch failed too
Trying again.
Comment #4
arpeggio CreditAttribution: arpeggio commentedHi 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
Comment #5
marcelovaniComment #6
marcelovaniHi 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.
Comment #7
arpeggio CreditAttribution: arpeggio commentedHi 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):
Comment #8
marcelovani@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]
Comment #10
welly CreditAttribution: welly commentedThe 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?