Answers.Body: <p>After some testing the answer to this was that I needed to setup custom CP routes to pass the <code>offset</code> variable from template to controller and back to template.</p>
  
  <pre><code>public function registerCpRoutes(){
      return array(
          'tumblr/offset' =&gt; array('action' =&gt; 'tumblr/offset')
      );
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-04T22:33:37.220Z
Answers.LastActivityDate: 2016-10-04T22:33:37.220Z
Answers.UserDisplayName: JMP
Body: <p>Trying to add an <code>actionUrl</code> to this plugin. 
  When I set <code>offset</code> manually to a number, everything works, so I think the controller is working properly. </p>
  
  <p>I can't seem to get the <code>offset</code> from the button using getParam (or anything else).</p>
  
  <p>What's the best way to get a <code>offset</code> back into the template?</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Craft;
  
  class TumblrController extends BaseController{
  
      public function actionOffset(){
  
          $offset = craft()-&gt;request-&gt;getRequiredParam('offset', null);
  
          craft()-&gt;tumblr-&gt;getSubmissionData($offset);
  
          $this-&gt;redirect($_SERVER['HTTP_REFERER']);
      }
  }
  </code></pre>
  
  <p><strong>Service</strong></p>
  
  <pre><code>public function getSubmissionData($offset){
  
  $submission_data = array();
  
  // some variables that will be pretttty useful
  $settings       = craft()-&gt;plugins-&gt;getPlugin('tumblr')-&gt;getSettings();
  $publicKey      = 'example';
  $secretKey      = 'example';
  $token          = 'example';
  $tokenSecret    = 'example';
  $callback_url   = 'tumblr/callback';
  $blogName       = 'example.tumblr.com';
  
  $client = new \Tumblr\API\Client($publicKey, $secretKey, $token, $tokenSecret);
  
  //SETTING UP OFFSET
  //$offset = (!isset($offset) || is_null($offset)) ? '0' : $offset; 
  
  $submissions = $client-&gt;getSubmissionPosts($blogName, array('offset' =&gt; $offset, 'limit' =&gt; 50));
  
  $i = 0;
  
  foreach($submissions-&gt;posts as $submission) {
      $i++;
      foreach($submission as $key =&gt; $value){
          if ($key == "timestamp" || $key ==  "publisher" || $key == "video_type" || $key == "thumbnail_url" || $key == "thumbnail_width" || $key == "thumbnail_height" ||     $key == "html5_capable" || $key == "id" || $key == "short_url" || $key == "video" || $key == "content_raw" || $key == "player" || $key == "highlighted" || $key     == "photos" || $key == "trail" || $key == "tags" || $key == "description" || $key == "reblog" || $key == "followed" || $key == "blog_name" || $key ==     "reblog_key" || $key == "liked" || $key == "note_count" || $key == "link_author" || $key == "excerpt" || $key == "can_send_in_message" || $key == "can_reply" ||     $key == "recommended_source" || $key == "recommended_color" || $key == "font" || $key == "background" || $key == "format" || $key == "post_url" || $key ==     "slug" || $key == "is_submission" || $key == "is_anonymous")
              continue;
          $submission_data[$i][$key][] = isset($value) ? $value : "Nothing set"; 
  
      } 
  }
  
  
  $charset = craft()-&gt;templates-&gt;getTwig()-&gt;getCharset();
  $twig_html = new \Twig_Markup(json_encode($submission_data), $charset);
  
  $tagdata = $submission_data;
  foreach($submission_data as $key =&gt; $value){
      foreach($value as $k =&gt; $v){
          $tagdata = str_replace("{".$key."}", $v[0], $submission_data);
      }
  }
  
  // // // // replace the embed code with the Twig object
  $tagdata['embed_code'] = $twig_html;
  
  
  return $tagdata;
  }
  </code></pre>
  
  <p><strong>Template</strong></p>
  
  <pre><code>{% extends "_layouts/cp" %}
  {% set title = "Tumblr Submissions"|t %}
  {% includeCssResource "tumblr/css/table.css" %}
  
  {% set offset = craft.request.getParam('offset') %}
  {% set submissions = craft.tumblr.submissions(offset) %}
  
  {% block content %}
  
  &lt;pre&gt;{{ dump(offset) }}&lt;/pre&gt;
      &lt;div id="page-wrap"&gt;
          {% for i in range(1, 10, 1) %}
              &lt;a href="{{ actionUrl('tumblr/offset', {offset: i}) }}"&gt;&lt;button type="button"&gt;{{i}}&lt;/button&gt;&lt;/a&gt;
          {% endfor %}
          &lt;table class="table"&gt;
              {% for key,submit in submissions %}
                  {% if loop.index == 1 %}
                      &lt;thead&gt;
                          &lt;tr class="row header"&gt;
                              {% for ref,items in submit %}
                                  &lt;th class="cell"&gt;{{ ref }}&lt;/th&gt;
                              {% endfor %}
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                  {% endif %}
                      &lt;tr class="row"&gt;
                          {% for ref,items in submit %}
                              &lt;td class="cell"&gt;{{ items[0]|e }}&lt;/td&gt;
                          {% endfor %}
                      &lt;/tr&gt;
              {% endfor %}
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  {% endblock %}    
  </code></pre>
  
Tags: <plugin-development><plugins>
Title: Plugin ActionUrl not being set
ThreadText: # Plugin ActionUrl not being set
  
  (Asked by: username_0 on 2016-10-04)
  
  Trying to add an `actionUrl` to this plugin.
  When I set `offset` manually to a number, everything works, so I think the controller is working properly.
  
  I can't seem to get the `offset` from the button using getParam (or anything else).
  
  What's the best way to get a `offset` back into the template?
  
  **Controller**
  
  ```
  <?php
  
  namespace Craft;
  
  class TumblrController extends BaseController{
  
      public function actionOffset(){
  
          $offset = craft()->request->getRequiredParam('offset', null);
  
          craft()->tumblr->getSubmissionData($offset);
  
          $this->redirect($_SERVER['HTTP_REFERER']);
      }
  }
  
  ```
  
  **Service**
  
  ```
  public function getSubmissionData($offset){
  
  $submission_data = array();
  
  // some variables that will be pretttty useful
  $settings       = craft()->plugins->getPlugin('tumblr')->getSettings();
  $publicKey      = 'example';
  $secretKey      = 'example';
  $token          = 'example';
  $tokenSecret    = 'example';
  $callback_url   = 'tumblr/callback';
  $blogName       = 'example.tumblr.com';
  
  $client = new \Tumblr\API\Client($publicKey, $secretKey, $token, $tokenSecret);
  
  //SETTING UP OFFSET
  //$offset = (!isset($offset) || is_null($offset)) ? '0' : $offset; 
  
  $submissions = $client->getSubmissionPosts($blogName, array('offset' => $offset, 'limit' => 50));
  
  $i = 0;
  
  foreach($submissions->posts as $submission) {
      $i++;
      foreach($submission as $key => $value){
          if ($key == "timestamp" || $key ==  "publisher" || $key == "video_type" || $key == "thumbnail_url" || $key == "thumbnail_width" || $key == "thumbnail_height" ||     $key == "html5_capable" || $key == "id" || $key == "short_url" || $key == "video" || $key == "content_raw" || $key == "player" || $key == "highlighted" || $key     == "photos" || $key == "trail" || $key == "tags" || $key == "description" || $key == "reblog" || $key == "followed" || $key == "blog_name" || $key ==     "reblog_key" || $key == "liked" || $key == "note_count" || $key == "link_author" || $key == "excerpt" || $key == "can_send_in_message" || $key == "can_reply" ||     $key == "recommended_source" || $key == "recommended_color" || $key == "font" || $key == "background" || $key == "format" || $key == "post_url" || $key ==     "slug" || $key == "is_submission" || $key == "is_anonymous")
              continue;
          $submission_data[$i][$key][] = isset($value) ? $value : "Nothing set"; 
  
      } 
  }
  
  $charset = craft()->templates->getTwig()->getCharset();
  $twig_html = new \Twig_Markup(json_encode($submission_data), $charset);
  
  $tagdata = $submission_data;
  foreach($submission_data as $key => $value){
      foreach($value as $k => $v){
          $tagdata = str_replace("{".$key."}", $v[0], $submission_data);
      }
  }
  
  // // // // replace the embed code with the Twig object
  $tagdata['embed_code'] = $twig_html;
  
  return $tagdata;
  }
  
  ```
  
  **Template**
  
  ```
  {% extends "_layouts/cp" %}
  {% set title = "Tumblr Submissions"|t %}
  {% includeCssResource "tumblr/css/table.css" %}
  
  {% set offset = craft.request.getParam('offset') %}
  {% set submissions = craft.tumblr.submissions(offset) %}
  
  {% block content %}
  
  <pre>{{ dump(offset) }}</pre>
      <div id="page-wrap">
          {% for i in range(1, 10, 1) %}
              <a href="{{ actionUrl('tumblr/offset', {offset: i}) }}"><button type="button">{{i}}</button></a>
          {% endfor %}
          <table class="table">
              {% for key,submit in submissions %}
                  {% if loop.index == 1 %}
                      <thead>
                          <tr class="row header">
                              {% for ref,items in submit %}
                                  <th class="cell">{{ ref }}</th>
                              {% endfor %}
                          </tr>
                      </thead>
                      <tbody>
                  {% endif %}
                      <tr class="row">
                          {% for ref,items in submit %}
                              <td class="cell">{{ items[0]|e }}</td>
                          {% endfor %}
                      </tr>
              {% endfor %}
              </tbody>
          </table>
      </div>
  {% endblock %}    
  
  ```
  
  **Tags:** plugin-development, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-10-04. Score: 1 | Accepted answer
  
  After some testing the answer to this was that I needed to setup custom CP routes to pass the `offset` variable from template to controller and back to template.
  
  ```
  public function registerCpRoutes(){
      return array(
          'tumblr/offset' => array('action' => 'tumblr/offset')
      );
  }
  
  ```
  
  
  ---
  
  