1

I'm trying to add an offset parameter to the options loop within a Channel Entries form. While it accepts a limit, it simply ignores the offset. Here's an example:

{exp:channel:form channel="channel1"}
  {options:channel_name limit="4" offset="4"}       
    {option_name}
    # limit="4" works, offset="4" doesn't 
  {options:channel_name}
{/exp:channel:form} 

How can I add an offset? I'm using this on a channel form.

2
  • Hi Franz, I see you've made this to a new question! :) Can you let us know what type of field channel_name is? Is it a relationship field, checkboxes, select list or otherwise? I was going to write a quick example to see if I could debug this. interesting that limit works, looking through the code I don't even see it being supported!!!!
    – Blatant
    Commented May 22, 2015 at 9:24
  • Hi @Blatant! Thanks for your help :) This is a relationship field rendered using radio buttons. I also found it interesting that limit works while offset doesn't.
    – Franz
    Commented May 24, 2015 at 18:43

1 Answer 1

1

A word of warning, you could achieve this with PHP on a template (though some here don't like the idea of PHP on templates!).

Instead of tring to use the limit/offset syntax, lets push out options into a PHP array, then we'll do the array limits and offsets ourselves!

PHP On = Output

<?php
$options = array();
function print_options($limit, $offset){
  foreach( array_slice($options, $offset, $limit, true) as $option ) { 
    print $option;
  }
} 
?>
{exp:channel:form channel="channel1"}
  {options:channel_name}       
    <?php $options[] = '<option value="{option_value}">{option_name}</option>'; ?>
  {options:channel_name}

  <select>
    <?php print_options(4, 4); ?>
  </select>
{/exp:channel:form} 

Untested but hopefully you'll get the idea if I've not type-o'd in my code...

Edit: Simpler version, removed unneeded function and potential var scope issue.

PHP On = Output

{exp:channel:form channel="channel1"}
  {options:channel_name}       
    <?php $options[] = '<option value="{option_value}">{option_name}</option>'; ?>
  {options:channel_name}

  <select>
    <?php 
      //array_slice parameters = options array, limit, offset, preseveKeys
      foreach( array_slice($options, 4, 4, true) as $option ) { 
        print $option;
      }
    ?>
  </select>
{/exp:channel:form} 
2
  • Thanks for the snippet. I've turned PHP On, parsed on output. Here's the PHP error I get: A PHP Error was encountered; Severity: Notice; Message: Undefined variable: options; Filename:; libraries/Functions.php(688) : eval()'d code; Line Number: 209. Here's the full error list: gist.github.com/franzos/c8d057e9f0632253f7f9
    – Franz
    Commented May 24, 2015 at 18:44
  • Looks like a PHP scope issue, try adding the $options array to the parameters of the print_options function and passing it in, Or see my edit which gets rid of the function, not really needed.
    – Blatant
    Commented May 26, 2015 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.