Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

SmartyPaginate ID problems...

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
chidera
Smarty Rookie


Joined: 08 Dec 2004
Posts: 22

PostPosted: Tue Feb 01, 2005 5:05 pm    Post subject: SmartyPaginate ID problems... Reply with quote

Hello,

I had no problems getting SmartyPaginate to work "out of the box" according to the basic examples given in the docs.

However, I'm having a terrible time getting it to work with non-default IDs.

Basically, I'm using SmartyPaginate to provide the pagination functionality for various pages in a website I'm building. But, it seems I need to provide different IDs in order to get each page to "act independently".

The problems SEEM to be centered around paginate_prev and paginate_next. Perhaps others, but that's about all I'm using right now.

In the template code, I do the following:
{paginate_prev id="csNews"}

I put code in paginate_prev to show the variable, $_id, and it always displays "default".

So....Any ideas? Smile

Thanks in advance.

Travis
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Tue Feb 01, 2005 5:07 pm    Post subject: Reply with quote

Upgrade to the CVS version, there was a bug fix in the custom functions.
Back to top
View user's profile Send private message Visit poster's website
chidera
Smarty Rookie


Joined: 08 Dec 2004
Posts: 22

PostPosted: Tue Feb 01, 2005 5:19 pm    Post subject: Reply with quote

Hi,

Thanks for the incredibly quick reply!

When were the changes made? I thought I had the "latest and greatest".

I also found that I had made a mistake. I had two pages, news and articles. I THOUGHT I had put the IDs in the right place, but I had put them in only one of the two pages, and it was the wrong one.

So....I'll wait for your reply on when the changes were made and then go from there.

BTW, who does one talk to when one wants to contribute? For example, I added a variable to the paginate_prev and paginate_next functions that allow the caller to dictate whether or not the text is always returned. This is nice for when someone wants it to SAY, "Next", even when there's no link. Let me know. It's simple enough, but I'll share the code if there's a need/desire.

Thanks again, and take care.

Travis
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Tue Feb 01, 2005 5:25 pm    Post subject: Reply with quote

You probably have the latest release from Oct 12th. There have been three changes to CVS thus far:

* fix bug in paginate_* UrlVar setting (Fernando_AndrX, monte)
* fix functions paginate_* urls to be XHTML compliant (kilburn, monte)
* add the assign() method and new {$paginate} vars to the README (monte)


As for your text returned, do you mean assigned instead of output? Or something else? You can change the text of the prev/next links already...
Back to top
View user's profile Send private message Visit poster's website
chidera
Smarty Rookie


Joined: 08 Dec 2004
Posts: 22

PostPosted: Tue Feb 01, 2005 5:51 pm    Post subject: Reply with quote

Thanks for the info.

Yes, it does seem as though I have the latest release from October 12th. But, I'll look closer at the CVS to see what's new and then consider updating.

When I was talking about paginate_*, I mean this:
The visitor is on the first "page" of several pages. Calling paginate_next will return a valid link, or whatever, that the user can click on to go to the next page. But, paginate_prev will NOT return anything, since it's on the first page. I propose an optional parameter that will allow the caller to say whether or not they want the text returned, even when there is no "previous" page. I prefer this way, personally, because the navigation layout doesn't change too much. The word "Previous" (or whatever is the previous text) will appear, but it will not have a link.

Here's the code I wrote, which may help:

Code:
function smarty_function_paginate_prev($params, &$smarty) {

   $_id = isset($params['id']) ? $params['id'] : 'default';
   if (!class_exists('SmartyPaginate')) {
      $smarty->trigger_error("paginate_prev: missing SmartyPaginate class");
      return;
   }
   if (!isset($_SESSION['SmartyPaginate'])) {
      $smarty->trigger_error("paginate_prev: SmartyPaginate is not initialized, use connect() first");
      return;
   }
   if (!isset($_SESSION['SmartyPaginate'][$_id]['item_total'])) {
      $smarty->trigger_error("paginate_prev: total was not set");
      return;
   }

   $_url = $_SESSION['SmartyPaginate'][$_id]['url'];

   $_text = isset($params['text']) ? $params['text'] : $_SESSION['SmartyPaginate'][$_id]['prev_text'];
   if(($_item = SmartyPaginate::_getPrevPageItem($_id)) !== false) {
      $_show = true;
      $_url .= (strpos($_url, '?') === false) ? '?' : '&';
      $_url .= SmartyPaginate::getUrlVar() . '=' . $_item;
   } else {
      $_show = false;
   }
   return $_show ? '<a href="' . $_url . '">' . $_text . '</a>' : (($params['showAlways'] == true) ? $_text : '');
}


As you can see, I just changed a little bit. If the user passes "showAlways" as true, then the text is returned even when there's no link.

I did the same with paginate_next, too, and would be happy to share the code if that's something you want.

I would also like to see paginate_first and paginate_last. I haven't yet done the work myself, but I will when time allows IF it's not already been added. Smile

Thanks again.

Travis
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Tue Feb 01, 2005 6:00 pm    Post subject: Reply with quote

I like the idea of prev/next links showing up without links. I think a good way to make it work is make it print prev/next by default, and optionally allow the links to be omitted with flag show_empty=false or something similar.

The first/last is also a good idea! There has also been a suggestion to add functionality to prev_middle so you can control how many page links show up, so instead of:

[1] [2] [3] [4] [5] [6] (all the way to 100)

you could have:

... [88] [89] [90] [91] ...

Not simple, but doable. If you want to work on any of these features that would be great. Otherwise I might if I find the time Wink
Back to top
View user's profile Send private message Visit poster's website
chidera
Smarty Rookie


Joined: 08 Dec 2004
Posts: 22

PostPosted: Tue Feb 01, 2005 6:09 pm    Post subject: Reply with quote

Hi,

Yes, either way is fine. It just depends on which way people might go most. Perhaps a poll is in order...?

I agree with the others on paginate_middle, too. I don't use it -- yet -- for just the reason you noted. I would like a bit more control over it. I had rolled my own sort of functionality some time back. There may be something valuable I could contribute. It may be code that's too shameful to show anyone, though. Wink

I'd be happy to share my SmartyPaginate "extensions" with the "group". As soon as I code a paginate_first/paginate_last, I'll let you all know. And, anything else I do, for that matter. The problem, as I'm sure everyone else knows, is a problem of time. Neutral

Anyway, thanks for the help and the feedback. I'll be back in here if/when I have more questions or something (potentially) valuable to contribute.

Take care,

Travis
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP