adrianmak Posted February 27, 2015 Share Posted February 27, 2015 Learn from skyscrapper pw profile, it is easy to output a list of content with pagination with just a line of code $content = $page->children("limit=10")->render(); However, it output title only. How to output other fields ? for example, summary of content, an image, Link to comment Share on other sites More sharing options...
Soma Posted February 27, 2015 Share Posted February 27, 2015 Maybe have a good read on the module itself? https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Markup/MarkupPageArray.module 1 Link to comment Share on other sites More sharing options...
adrianmak Posted February 27, 2015 Author Share Posted February 27, 2015 I read the pageArray. I could provide user option to supply more fields to render. I have a question, My page fields setup doesn't has a summary field, all content are put in body field. I could write a small utility function to output say first 20 words. Could it be possible to put in the option markup say teaser({body}) ? function teaser($str, $num) { $words = explode(" ", $str); $first = join(" ", array_slice($words, 0, $num)); return $first; } Link to comment Share on other sites More sharing options...
BitPoet Posted February 28, 2015 Share Posted February 28, 2015 Why not write a small module that hooks before pageSave and fills a hidden summary field with the teaser generated with your function? That way, you'll also save memory by only running the function once in the backend and not with every listing of your page. Link to comment Share on other sites More sharing options...
bernhard Posted February 28, 2015 Share Posted February 28, 2015 i'm not sure if i understand your questions correctly... Learn from skyscrapper pw profile, it is easy to output a list of content with pagination with just a line of code $content = $page->children("limit=10")->render(); However, it output title only. How to output other fields ? for example, summary of content, an image, do you mean something like this? $items = $page->children('limit=10'); foreach($items as $item) { echo '<h1>' . $item->title . '</h1>'; echo $item->body; echo $item->whatsoever; } echo $items->renderPager(); is this question related to your first question? I read the pageArray. I could provide user option to supply more fields to render. I have a question, My page fields setup doesn't has a summary field, all content are put in body field. I could write a small utility function to output say first 20 words. Could it be possible to put in the option markup say teaser({body}) ? function teaser($str, $num) { $words = explode(" ", $str); $first = join(" ", array_slice($words, 0, $num)); return $first; } are you looking for truncating text?? https://processwire.com/talk/topic/2849-text-output-limiter/?p=71561 Link to comment Share on other sites More sharing options...
Soma Posted February 28, 2015 Share Posted February 28, 2015 This helper render method on PageArray's is usually meant for a convenient tool when developing like scaffolding (although you can't CRUD). Although it is there to use if you want, I also always use the renderPager() method. If you want to output a summary but haven't got a summary field $page->summary. Since you can't modify the module, one could add the property to page object via property hook. Which means to add a property on runtime. You can see an example in the HelloWorld.module. Something like this will give you a $page->summary $pa = $pages->find("template=basic-page, limit=4"); wire()->addHookProperty("Page::summary", null, function($event){ $page = $event->object; $event->return = $page->headline; // return something for "summary" }); $content .= $pa->render(array('itemMarkup'=>"\n\t<li><a href='{url}'>{title}<br><small>{summary}</small></a></li>")); But what's wrong with creating your own foreach? $pa = $pages->find("template=basic-page, limit=4"); if($pa->count) { $list = ""; foreach($pa as $p){ $summary = limitWords($page->body); // your function to limit words maybe $list .= "<li><a href='{$page->url}'>{$page->title}<br><small>{$summary}</small></a></li>"; } $content .= "<ul>$list</ul>"; $content .= $pa->renderPager(); } else { $content .= "Nothing found"; } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now