Skip to content

Instantly share code, notes, and snippets.

@leevigraham
Created July 11, 2013 09:13
Show Gist options
  • Save leevigraham/5973907 to your computer and use it in GitHub Desktop.
Save leevigraham/5973907 to your computer and use it in GitHub Desktop.
<?php
$EE = get_instance();
$limit = $EE->input->get('show-all') ? 100 : 3;
?>
{exp:channel:entries limit="<?php print($limit); ?>"}{/exp:channel:entries}
@ckimrie
Copy link

ckimrie commented Jul 11, 2013

I know this is likely to be quick and illustrative of how to solve the problem and not for production, but I thought I'd highlight my typical route: The wrapper plugin.

index.html

{exp:myplugin:parse_limit parse='inwards'}
    {exp:channel:entries limit="{custom_limit}"}
        ...
    {/exp:channel:entries}
{/exp:myplugin:parse_limit}

pi.myplugin.php

<?php

// ...

function parse_limit() {
    $EE = get_instance();
    $limit = $EE->input->get('show-all') ? 100 : 3;
    return $EE->TMPL->parse_variables_row($EE->TMPL->tagdata, array('custom_limit' => $limit));
}

//...

This allows you to get away with not having PHP enabled in templates but then also parse a whole array of URI query strings and then feed them into a Channel entries tag. For more advanced usage you can even initialise the Channel class yourself and forego the need for the channel:entries tag altogether.

Just FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment