Jump to content

how to styling of the output content of pagnation


adrianmak
 Share

Recommended Posts

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

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

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

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

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";
}
  • Like 1
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...