Jump to content
j00st

$page->next devaluated/replaced?

Recommended Posts

Hi guys and gals!

I'm pretty new to ProcessWire, and trying to figure out as much as I can myself, but I'm totally stuck on this little piece though.

• I've got a one-page scrollable site, and am using hashtags to jump to the next area (which is incidentally of course also a $page)

• what I'm looking to do is link the next-page to an href, so I figured I could use $page->next, but that gives me a number (1007 in this case). Same goes for the siblings.

What I thought would happen would be the following; just as $page->name gives me the current name (and thus the current hashtag) I figured 'next' would give me the name of the 'next' page. But I probably didn't do my homework.

$page->next->name gives me 1007->name so that clearly isn't working. So to end this query:

How do I get the name of the next page displayed so I can use it in my href?

thanks for the help!

p.s.:

->next is shown here: http://processwire.com/api/variables/page/

but not here: http://processwire.com/api/cheatsheet/

Share this post


Link to post
Share on other sites

$page->next->url is what you are looking for.

Share this post


Link to post
Share on other sites

Hi and welcome to the forums!

You're definitely on the right track, just a little PHP to be learned I think :). I guess you've tried something like this:

echo "$page->next->name";

To make it work you need to add some curly braces, like this:

echo "{$page->next->name}";

And probably you're actually after url rather than name (as Soma says above, it seems).

Share this post


Link to post
Share on other sites

Next is shown on cheatsheet aswell. So next gives you the next page in the tree or array and if you echo it it gives you the id only, so you have to add the field you need , in your case ->name.

  • Like 1

Share this post


Link to post
Share on other sites

Sorry I was on mobile and didn't read carefully... I think Nik is right.

And I think you have "advanced" diabled on cheatsheet, that's why you don't see it :D

Share this post


Link to post
Share on other sites

Hey nik & Soma! first off; thanks for the quick replies! :D

Both right - I did have the 'advanced' disabled, so I didn't see the ->next, won't make that mistake again anytime soon,

and indeed, some php was to be learned, the curly braces did it!

I ended up using ->name, because I'm echoing it into an href reference, and using hashchange event to scroll down to the correct page

it's working now though, so thanks again!

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DV-JF
      Hey all, hope you're feeling well these days!
      Short question: Under "Setup > Templates" it's possible to sort the templates by last modified. Is this possible for fields view to?
      Long explanation:
      Currently I am in the process of programming a reusable template and often have to copy several fields & templates from different PW installations into my "master version".
      Therefore it would be good to see already in the field list when the last modification has taken place.
      Stay healthy & don't forget to wash you hands - many greets!
    • By AndZyk
      Hello,
      I am currently building a intranet with hundreds of posts. One planned feature is, that each logged-in user can see what post he has already read.
      So I have added a page reference field „readPosts“ to the user template and save each post as page to this page reference field when visiting the post.
      This could lead to hundreds of pages in this single page reference field. Because of this I was wondering, if anybody has experience in how good the page reference field can scale? Can it handle hundreds of page references or could there be a downside to the performance? As far as I can see, in the database only the user id, page id and sort number would be saved. So theoretically there would be no performance issue.
      The alternativ would be to save the user directly in the post as page reference. Would that be the better solution? 😉
      Regards, Andreas
    • By Roberts R
      I have simple page structure:
      category subcategory simple-product simple-product simple-product simple-product subcategory .... category2 so Im at category page and running
      $pages->find("template=simple-product, has_parent=$page, limit=8"); and it returns 0 pages
       
      but this returns 4 pages
      $pages->find("template=simple-product, has_parent=$page"); Can someone explain why limit does not work here?
      EDIT:
      So I did some tests and it seems that any limit=n where n is >= actual page count that is possible ... selector return 0 results.
    • By Lmwt
      Hi forum,
      I have this list of fields with labels and I want to skip the displaying of labels for fields left empty (e.g. if field "logo" is not filled with an image, but it could also be text fields). Using count() and "continue" will always output either nothing or all labels.
      Is there a way to use the "skipLabel" method in the loop?
      foreach ($page->template->fields as $field) { if(!count($page->$field->logo)) {continue;} else { $etikette = $field->getLabel(); //get label in the current user language $content .= " <br><li class='pub-field'>$etikette<br> </li>"; //display labels as li $content .= $page->get($field->name) . "<br>"; // display values as li } } Thanks for your help!
    • By Lmwt
      Hello,
      and one more beginner question: I am using the multi-language site profile and having troubles targeting the region I want to populate in my templates due to delayed output. The list is now appearing on top of the nav bar 🙂 and the values of the fields on one line down the title. I want these fields to be displayed in a list underneath the title of the page, and I also would like the name of the field to be displayed as a string in front of the value... I dont know how to do this. Can someone help?
      right now my code looks like this: 
      <?php namespace ProcessWire;?> <!DOCTYPE html> <html> <li class="Pub-profile-info"><?php $content .=page()->Location?></li> <li class="Pub-profile-info"><?php $content .=page()->Pub_country?></li> <li class="Pub-profile-info"><?php $content .=page()->Since?></li> <li class="Pub-profile-info"><?php $content .=page()->Contact?></li> <li class="Pub-profile-info"><?php $content .=page()->Focus?></li> <li class="Pub-profile-info"><?php $content .=page()->Members?></li> <li class="Pub-profile-info"><?php $content .=page()->Location?></li> <li class="Pub-profile-info"><?php $content .=page()->Decision_making?></li> <li class="Pub-profile-info"><?php $content .=page()->Financing?></li> <li class="Pub-profile-info"><?php $content .=page()->History?></li> <li class="Pub-profile-info"><?php $content .=page()->images?></li> <li class="Pub-profile-info"><?php $content .=page()->logo?></li> </html> and the screen looks like that:
      Thanks for helping!

×
×
  • Create New...