ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Has anyone found a way to show pagination while using dynamic parameters?

September 21, 2010 12:00pm

Subscribe [7]
  • #1 / Sep 21, 2010 12:00pm

    webvox

    25 posts

    Just learned in mid-project about a major (for me) limitation to EE: the inability to use dynamic parameters and pagination on the same template. I’m not looking to vent or start a whine session here, just hoping to find someone who may have found a hack, plug-in or third party tool that gets around this limitation.

    Any ideas or suggestions from anyone?

  • #2 / Sep 21, 2010 7:17pm

    hd 

    156 posts

    Would you happen to have an example of your code, so that we can get a better idea of exactly what you are trying to do?

  • #3 / Sep 22, 2010 9:25am

    Mark Croxton

    319 posts

    The solution would be to wrap the exp:channel tag in a custom plugin that registers the dynamic parameter and then replaces a variable placeholder. Eg, let’s say orderby was your dynamic parameter:

    {exp:my_plugin parse="inward"}
    {exp:channel:entries channel="news" limit="15" paginate="both" orderby='{orderby}' }
    {/exp:my_plugin}

    my_plugin would determine the value of $_POST[‘orderby’] and then parse the tag data (contained in $this->EE->TMPL->tagdata) and replace {orderby} with the value, then return it.

    EDIT: someone’s already written a plugin that does this (EE 1.6.x) (just remember to use parse=“inward”):
    http://devot-ee.com/add-ons/get-post-parameters/

  • #4 / Sep 22, 2010 10:14am

    webvox

    25 posts

    @hd - here’s what I’m working on: I have a template that displays a range of products that belong to different categories. I’d like to allow visitors to filter and limit the display (show only 24 or 36 products) and browse the resulting pages. In some cases, there are a hundred or more products that could be listed.

    I’m using {paginate} {pagination_links} {/paginate} to generate the pagination, and the following code to allow the dynamic parameters: {exp:channel:entries channel="products" status="open" dynamic_parameters="limit|category" paginate="both"}. The parameters are driven by a couple of dropdowns that choose the limit and select the category filter. Unfortunately I’ve hit the limitation of not being able to have both dynamic parameters and pagination. I’m hoping this is a common enough need that someone has found a workaround. I’ve also put in a feature request so there’s always that hope.  : )

    @Mark Croxton - I appreciate the details about the custom plugin approach. That sounds like something I need to look more closely at, though being new with EE, I’m not sure I have time to build a custom plugin before the site needs to launch. I’ll definitely go back to explore that option. Unfortunately, I’m building with EE 2 so the plugin you mention won’t work for me. It could provide a blueprint if I go down the custom plugin path, though.

    I appreciate the replies, folks, and I’m open to any suggestions.

  • #5 / Sep 22, 2010 10:18am

    Mark Croxton

    319 posts

    Building a plugin as I described would be trivial. It will take you all of 10 minutes:

    http://ellislab.com/expressionengine/user-guide/development/plugins.html

  • #6 / Sep 22, 2010 12:22pm

    webvox

    25 posts

    Dude, I’m just getting my head wrapped around parameters and variables and such, so it’ll probably take me more like 20 minutes. :D

    With that said, it doesn’t look too bad actually. From the article and your example, I can see how a plugin might be used. If I understand this correctly, the correct approach would be to create a plugin that captures a user-selected variable—- like “4” from a dropdown—- and then processes that input to then display 4 items. Am I correct?

  • #7 / Sep 22, 2010 12:31pm

    Mark Croxton

    319 posts

    Right. Replace ‘orderby’ with ‘limit’ in the above example.

  • #8 / Sep 22, 2010 12:45pm

    webvox

    25 posts

    Excellent! I’ll definitely take a look at a custom plugin for my solution. Thanks for the suggestion and clarification, Mark. Much appreciated!

  • #9 / Sep 22, 2010 1:37pm

    webvox

    25 posts

    Mark: just dropped you a PM. If you have an opportunity, let’s touch base off-forum.

  • #10 / Sep 24, 2010 10:54am

    Mark Croxton

    319 posts

    I was a bit glib earlier, I hadn’t considered that the POSTed form values would need to be persisted across page views. So anyway, I wrote the plugin but haven’t actually tested it yet.

    http://github.com/croxton/get_parameters

    Let me know if it works.

  • #11 / Dec 17, 2010 4:10pm

    heaversm

    197 posts

    Any chance you can create an EE1 version of this? I’ve been struggling for quite some time now trying to resolve this exact problem

  • #12 / Dec 20, 2010 6:19am

    Mark Croxton

    319 posts

    I’ll have a look at a 1.x version in the new year, but no promises.

    I have used the same functionality extensively in 1.x but usually as part of custom modules and plugins. The persist function is a follows:

    EDIT: assumes you have variable $this->fields in your class

    /** 
         * Either fetches form field data from the $_POST array, saves to cookie and populates $fields array
         * Or, if $_POST is not set retrieve values, populates $_POST and $fields from the cookie
         * @access private
         * @param array $fields
         * @return array
         */ 
        private function _fetch_fields($fields=array()) 
        {
            global $IN, $FNS;
            $cookie_name = strtolower(get_class($this));
            $cookie_length = .5; // hours
            
            if (count($_POST)>0)
            {
                // form submitted - get field values from $_POST and set $fields array
                foreach($fields AS $field) 
                {
                    // form just submitted - get cleaned-up POSTed values from $IN
                    if (!!$IN->GBL($field, 'POST'))
                    {
                        $this->fields[$field] = $IN->GBL($field, 'POST');
                    }
                }
                
                // now save to cookie (overwrites existing cookie if it exists)     
                $FNS->set_cookie($cookie_name, serialize($this->fields), 60*60*$cookie_length);
            } 
            else 
            {    
                // else retrieve cookie data, restore $fields and $_POST arrays
                if (!!$IN->GBL($cookie_name, 'COOKIE'))
                {
                    $this->fields = $_POST = unserialize($IN->GBL($cookie_name, 'COOKIE'));
                }
            }
            return $this->fields;
        }

    If you can understand what this is doing then you can use it in your own plugint o register and persist POSTed form values.

  • #13 / Dec 20, 2010 10:54am

    Rob Sanchez

    335 posts

    I just released Dynamo, a module that allows you to use pagination with dynamic parameters, by storing your parameters in the database for future use. Download and usage notes here: http://github.com/rsanchez/dynamo

  • #14 / Dec 21, 2010 3:02pm

    heaversm

    197 posts

    Is this an EE2 Plugin?

  • #15 / Dec 21, 2010 3:03pm

    Rob Sanchez

    335 posts

    Yes, EE2 only.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases