Jump to content

isellsoap

Members
  • Posts

    77
  • Joined

  • Last visited

Everything posted by isellsoap

  1. Hi there. I guess $pages->get("/features")->find("field1<=field2"); should be enough. Check out the selectors section in the API reference. Edit: Sorry, didn’t read your post right. Hm, it should also work with "<" of course. Strange.
  2. Uhm? I totally agree, but that wasn’t what I meant. Like for instance: if the pagination has 5 pages, is there a way to get the last page of that pagination so that when someone tries to go to "page6" I can throw an 404 exception?
  3. I guess it‘s just a matter of principle. Why would I want a page that doesn’t make sense at all but doesn’t throw an error? Better to throw an error. Do you know how to get the number of the last page generated in a pagination? Like I wrote in the starting post: But I got a solution by now.
  4. On a different note: I’d like to throw a 404 error when a page is reached where no content appears. E.g. pagination only goes until "page5" but when I type "page6" in the address bar it doesn’t throw an error. Can one of you reproduce this behaviour? I tested it a bit further and apparently the pagination limit is 999.
  5. Ha, I did it! Instead of $pa = new PageArray(); $value = $pages->find( "title%=$q" ); $pa->import( $pages->find( "template=abc, …|…|…=$value" ) ); $pa->import( $pages->find( "template=abc, title%=$q" ) ); I wrote this $pa = $pages->find( "template=abc, bla1.title|bla2.title|bla3.title|…|title%=$q, limit=4" ); I don’t search for the page references but for the titles of the page references with ".title". Works like a charm.
  6. Thanks for the clarification. Or another option would be to really do it just in one find(), but as ryan explained OR expressions in selectors aren’t supported (yet).
  7. Thanks, but I think I’m actually doing this already with $result = $pa->find( "start=0, limit=4" ); Or am I missing something?
  8. Hey there. The pagination for my search isn’t working. I guess it has something to do with the merging of PageArrays beforehand. Take a look at the (simplified) search.php: $out = ""; if ( $q = $sanitizer->selectorValue( $input->get->q ) ) { $input->whitelist( "q", $q ); $pa = new PageArray(); $value = $pages->find( "title%=$q" ); $pa->import( $pages->find( "template=abc, …|…|…=$value" ) ); $pa->import( $pages->find( "template=abc, title%=$q" ) ); $result = $pa->find( "start=0, limit=4" ); $pagination = $result->renderPager(); $count = count( $pa ); if( $count ) { $out .= "<h2>Search results found</h2>"; $out .= "<ul>"; foreach( $result as $r ) { $out .= "<li>{$r->title}</li>"; } $out .= "</ul>"; $out .= $pagination; } else { $out .= "<h2>Sorry, no results were found</h2>"; } } else { $out .= "<h2>Please enter a search term in the search box</h2>"; } include("./head.inc"); echo $out; include("./foot.inc"); Pagination names are activated for the search template and the output of the pagination list is correct. When I go to "page2", "page3", etc. the result is always the very first 4 matches. Any help is appreciated, thanks! p.s.: I have to do the merging because one time I search for page references to a page (the "…" in the code) and one time for the title of a page with the template "abc". (offtopic: if you know a better solution to this just let me know)
  9. Solved it. I just throw the exception at the top of the page, before the head.inc of that page is included. Now I can call head.inc in the 404 template without worrying.
  10. So there really isn’t a way to check if Wire404Exception is being called? I have the problem that when throw new Wire404Exception(); is being called, then the code of the 404 template is being included on the same page, but when another 404 occurs (e.g. the user typed a $input->urlSegment2 in the address bar, although only one segment is allowed) then only the 404 template is being called (that is without the inclusion of head.inc and foot.inc). Do you guys see what I mean? So I’d need a method to check if Wire404Exception is explicitly called, so I know when and when not to include head.inc and foot.inc in the 404 template.
  11. Sorry in advance for "abusing" this thread for my question: I have something like this (very simplified) code to iterate through all products and output e.g. the price: foreach ( $page->children as $product ) { echo $modules->get( "ShoppingCart" )->renderPrice( $product->sc_price ); } The output of products happens quite often on the website, so I wanted to source it out into a function, something like: function productListing( $base ) { $str = ""; foreach ( $base as $product ) { $str .= $modules->get( "ShoppingCart" )->renderPrice( $product->sc_price ); } return $str; } and call it like this: echo productListing( $page->children ); The problem with the function is that it doesn’t work. I get this error: Error: Call to a member function get() on a non-object So calling get() inside a function doesn’t work. Why?
  12. Just wanted to ask: are there any new developments regarding arjen’s request or does one still have to use the »front-end approach«? Thanks.
  13. Thanks for the clarification. In this case a == comparison would also work, right? If I remember correctly its just a bit slower than === comparison?
  14. Hey, thanks for the welcome. Now I get it. $page->rootParent by itself outputs an ID and therefor you can check if a page is the current one. Rather trivial, but I really didn’t see it. Thanks.
  15. I first asked this question on Twitter but I guess the forum is a better place to get a good answer. The following code is taken from the head.inc file of the default PW theme: // Create the top navigation list by listing the children of the homepage. // If the section we are in is the current (identified by $page->rootParent) // then note it with <a class='on'> so we can style it differently in our CSS. // In this case we also want the homepage to be part of our top navigation, // so we prepend it to the pages we cycle through: $homepage = $pages->get("/"); $children = $homepage->children; $children->prepend($homepage); foreach($children as $child) { $class = $child === $page->rootParent ? " class='on'" : ''; echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>"; } The definition of $page->rootParent from the cheatsheet: I understand, that if you have the following page structure … Home About ProjectsProject ASubproject 1 Project B … and calling $page->rootParent->title on »Subproject 1« outputs »Projects«. But why can I also check with it that a page is the »current« one like written in the above code ($child === $page->rootParent)? I guess the problem I have with this is that one method implies two different semantics (which confuses me). Just wanted to share my thoughts about this as I’m trying to truly »learn« PW form the inside out.
×
×
  • Create New...