Reputation:
I have a blog set up in modx revolution using the articles addon, but I'm having some trouble configuring certain parts of the pagination. My current call for the pagination looks like this:
[[!+page.nav:notempty=`<nav>[[!+page.nav]]</nav>`]]
I've added the following listing parameters to the getPage call, to removes the [[+first]] and [[+last]] template from the pagination, and insert a static "back to top" link:
&pageNavOuterTpl=`[[+prev]]<a href="#header">Back to top</a>[[+next]]`
However, one thing still doesn't work as I intend. By default the previous
and next
links disappear if there is no previous or next page. However I'd rather display them and make them inactive in such a case. That way the pagination always looks the same, but inactive parts can be grayed out.
It seems that include.getpage.php contains the following lines (which prevent the prev and next links to be shown when there are no pages to navigate to):
// lines 16 - 18
if (!empty($pagePrevTpl) && ($page - 1) >= 1) {
$nav['prev'] = getpage_makeUrl($modx, $properties, $page - 1, $pagePrevTpl);
}
// and lines 29 - 31
if (!empty($pageNextTpl) && ($page + 1) <= $pageCount) {
$nav['next'] = getpage_makeUrl($modx, $properties, $page + 1, $pageNextTpl);
}
Which makes sense, but prohibits me from displaying placeholders as I want to. So what I'm trying to achieve is something like this:
// example for lines 16 - 18
if (!empty($pagePrevTpl)) {
if (($page - 1) >= 1) {
$nav['prev'] = getpage_makeUrl($modx, $properties, $page - 1, $pagePrevTpl);
} else {
$nav['prev'] = x // where x = default value for prev (set with :default)
}
}
A simple else or elseif like the above would do the trick, but that would be gone after an upgrade. Anyone have any ideas on the best way to approach this? Is there a way to achieve what I want to do without the changes getting overwritten on an upgrade? With a property set or something? I'm hoping someone knows how to do this.
Upvotes: 1
Views: 2302
Reputation: 4486
This was kind of hard to accomplish with the current version of getPage
which is the snippet that Articles utilizes for pagination. There of I have made some changes to getPage
wish essentially adds two new options. One to enable the functionality and an other to optionally apply a CSS class to those placeholders.
Until my pull request has been handled, feel free to get the source here https://github.com/victorhaggqvist/getPage.
Upvotes: 0
Reputation: 166
For clarity: this answer was posted by the OP. I did this because none of the other answers were up to par (the posters never even responded to my comments/suggestions), and I don't want to give a 150pt. bounty for an answer that isn't good. Since SO automatically awards a bounty to given answers (without even offering the choice of not awarding it to the OP), I've decided to do it this way. I'd rather not award the bounty, than give it to someone who doesn't put in the effort for it.
So, since this is a bug in the Articles include.getpage.php snippet, I decided to solve it with php as well. So I used a snippet called nav.placeholder to insert a placeholder when necessary. It's called from the articles template like so:
<!-- Secondary Navigation -->
<!-- Insert the nav tag only when there is pagination -->
[[!+page.nav:notempty=`<nav>`]]
<!-- Call nav.placeholder snippet and test if placeholder is needed -->
[[!nav.placeholder? &nav=`[[!+page.nav]]` &before=`1`]]
<!-- Display regular pagination, without surrounding tags -->
[[!+page.nav:notempty=`[[!+page.nav]]`]]
<!-- Call nav.placeholder snippet and test if placeholder is needed -->
[[!nav.placeholder? &nav=`[[!+page.nav]]` &before=`0`]]
<!-- Insert the /nav tag only when there is pagination -->
[[!+page.nav:notempty=`</nav>`]]
This call passes the content of page.nav (with the nav
variable) to the snippet and tells it in which position of the menu it is with the before
variable (so it won't insert the placeholder at the wrong place).
The snippet itself looks like this:
if (strstr($nav, "Older") != false && $before == 1) {
return "insert 'newer' placeholder content here";
} elseif (strstr($nav, "Newer") != false && $before == 0) {
return "insert 'older' placeholder here";
}
I know this is all pretty hacky, and not very dynamic, but it works, won't be overwritten on upgrade and is all done in the cms without ugly js or css hacking.
Upvotes: 0
Reputation: 46
A possible solution might be to use javascript to check if the next and prev elements exist on the page. If they don't exist, add your inactive placeholders.
First step would be to wrap the [[+prev]] and [[+next]] placeholders in the ModX template, e.g.
<span id="prevwrapper">[[+prev]]</span>
<span id="nextwrapper">[[+next]]</span>
Next add some javascript to run on page load, something like (assuming the links have the id's "prev" and "next"):
if(!document.getElementById("prev")){
document.getElementById('prevwrapper').innerHTML = "<span class='inactive'>Prev</span>";
}
if(!document.getElementById("next")){
document.getElementById('nextwrapper').innerHTML = "<span class='inactive'>Next</span>";
}
Obviously this would only work if javascript is enabled, but it would move your code away from the core of the plugin and the core of ModX itself, avoiding issues with future upgrades.
Upvotes: 1
Reputation: 17
You can do a couple things. You can break it out of the articles and just use getPages snippet, though this will make it so you have to modify the snippet parameters to change settings rather than using the Articles options. This is probably the best way because if you upgrade Articles, it will replace any changes you make to the files (so you'll have to repeat your modified changes.)
Though, if you prefer to continue using the options in Advanced Settings in the container, you can also modify the following file:
core/components/articles/model/articles/articlescontainer.class.php
Search for this code:
<div class="paging">
<ul class="pageList">
[[!+page.nav]]
</ul>
</div>
You can modify this there. Just remember, if you update Articles, it will overwrite any changes made here.
Upvotes: 2