Body: <p>I'm beginning with Craft/Twig and am developing a plugin that gets data from a Restful XML feed, and I've successfully tested it on my template.</p>
  
  <p>Below, I have the working plugin code and a sample of the XML structure.  The actual data feed will return anywhere from a few to several hundred 'INTELLCONT' nodes per user ('Record').</p>
  
  <p>In order to improve readability, is it possible to paginate this feed data?  Would I implement it from the plugin (php) side or rather the (twig) template side?</p>
  
  <p>Here is the code I have so far:</p>
  
  <p>Twig template:</p>
  
  <pre><code>{% extends "_layout" %}
  
  {% block content %}
      &lt;h1&gt;test&lt;/h1&gt;
      {% set name_var = 'john-smith' %}
          {{ craft.aifeed.XmlVariable(name_var) }}   
  {% endblock %}
  </code></pre>
  
  <p>PHP Code (plugin):</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
      class AiFeedVariable
      {
              public function XmlVariable($optional = null)
          {
      $url = "test_bb.xml";  
  
      $xml = simplexml_load_file($url);
  
      $xml-&gt;registerXPathNamespace('a','http://www.digitalmeasures.com/schema/data');//
      $xml-&gt;registerXPathNamespace('dmd','http://www.digitalmeasures.com/schema/data-metadata');
  
      $secondary_user_id = $optional;
      $xml_report_abbrev_bb = $xml-&gt;xpath('//a:Record[@username="'.$secondary_user_id.'"]');
  
      if($xml_report_abbrev_bb){
          echo '&lt;br&gt;CONTYPE is...'.$xml_report_abbrev_bb[0]-&gt;INTELLCONT-&gt;CONTYPE;
          echo '&lt;br&gt;termId is...'.$xml_report_abbrev_bb[0]['termId'].'&lt;br&gt;';
          echo '&lt;br&gt;surveyId is...'.$xml_report_abbrev_bb[0]-&gt;attributes('dmd',true)['surveyId'].'&lt;br&gt;';
  
          $dmd_fields = $xml_report_abbrev_bb[0]-&gt;children('dmd',true);
  
          echo '&lt;br&gt;dmd:IndexEntry is...'.$dmd_fields[0]-&gt;attributes()['indexKey'].'&lt;br&gt;';
  
  
      } else {
          echo 'XPath query failed b';  
      }
  
       }
      } 
  
  
      ?&gt;
  </code></pre>
  
  <p>The XML file (test_bb.xml)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Data xmlns="http://www.digitalmeasures.com/schema/data" xmlns:dmd="http://www.digitalmeasures.com/schema/data-metadata" dmd:date="2012-01-03"&gt;
      &lt;Record userId="148" username="john-smith" termId="4" dmd:surveyId="12"&gt;
          &lt;dmd:IndexEntry indexKey="D" entryKey="Dylan" text="Dylan"/&gt;
          &lt;INTELLCONT id="14" dmd:originalSource="54TEX" dmd:lastModified="2017-04-18T10:54:29" dmd:startDate="2011-01-01" dmd:endDate="2011-12-31"&gt;
              &lt;CONTYPE&gt;Sales Tools&lt;/CONTYPE&gt;
              &lt;CONTYPEOTHER&gt;Sales History&lt;/CONTYPEOTHER&gt;
          &lt;/INTELLCONT&gt;
      &lt;/Record&gt;
  &lt;/Data&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-06T22:24:43.457Z
Comments.Text: I'm not sure what this has to do with Craft cms. It's more about your XML api and normal php than about Craft. Do you want to know how to create a paginate? There are plenty tutorials. You'll just define an offset and a limit for your XML data and show only records within the range.
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-07T20:52:24.230Z
Comments.Text: Thanks.  Is there anything out of the ordinary PHP pagination code to consider when using the PHP as a Craft cms plugin?
Comments.UserDisplayName: buck1112
Tags: <plugin-development><plugins><php><pagination><xml>
Title: Paginate Results from Restful XML Feed
ThreadText: # Paginate Results from Restful XML Feed
  
  (Asked by: username_0 on 2018-02-05)
  
  I'm beginning with Craft/Twig and am developing a plugin that gets data from a Restful XML feed, and I've successfully tested it on my template.
  
  Below, I have the working plugin code and a sample of the XML structure. The actual data feed will return anywhere from a few to several hundred 'INTELLCONT' nodes per user ('Record').
  
  In order to improve readability, is it possible to paginate this feed data? Would I implement it from the plugin (php) side or rather the (twig) template side?
  
  Here is the code I have so far:
  
  Twig template:
  
  ```
  {% extends "_layout" %}
  
  {% block content %}
      <h1>test</h1>
      {% set name_var = 'john-smith' %}
          {{ craft.aifeed.XmlVariable(name_var) }}   
  {% endblock %}
  
  ```
  
  PHP Code (plugin):
  
  ```
  <?php
  namespace Craft;
  
      class AiFeedVariable
      {
              public function XmlVariable($optional = null)
          {
      $url = "test_bb.xml";  
  
      $xml = simplexml_load_file($url);
  
      $xml->registerXPathNamespace('a','http://www.digitalmeasures.com/schema/data');//
      $xml->registerXPathNamespace('dmd','http://www.digitalmeasures.com/schema/data-metadata');
  
      $secondary_user_id = $optional;
      $xml_report_abbrev_bb = $xml->xpath('//a:Record[@username="'.$secondary_user_id.'"]');
  
      if($xml_report_abbrev_bb){
          echo '<br>CONTYPE is...'.$xml_report_abbrev_bb[0]->INTELLCONT->CONTYPE;
          echo '<br>termId is...'.$xml_report_abbrev_bb[0]['termId'].'<br>';
          echo '<br>surveyId is...'.$xml_report_abbrev_bb[0]->attributes('dmd',true)['surveyId'].'<br>';
  
          $dmd_fields = $xml_report_abbrev_bb[0]->children('dmd',true);
  
          echo '<br>dmd:IndexEntry is...'.$dmd_fields[0]->attributes()['indexKey'].'<br>';
  
      } else {
          echo 'XPath query failed b';  
      }
  
       }
      } 
  
      ?>
  
  ```
  
  The XML file (test\_bb.xml)
  
  ```
  <?xml version="1.0" encoding="UTF-8"?>
  <Data xmlns="http://www.digitalmeasures.com/schema/data" xmlns:dmd="http://www.digitalmeasures.com/schema/data-metadata" dmd:date="2012-01-03">
      <Record userId="148" username="john-smith" termId="4" dmd:surveyId="12">
          <dmd:IndexEntry indexKey="D" entryKey="Dylan" text="Dylan"/>
          <INTELLCONT id="14" dmd:originalSource="54TEX" dmd:lastModified="2017-04-18T10:54:29" dmd:startDate="2011-01-01" dmd:endDate="2011-12-31">
              <CONTYPE>Sales Tools</CONTYPE>
              <CONTYPEOTHER>Sales History</CONTYPEOTHER>
          </INTELLCONT>
      </Record>
  </Data>
  
  ```
  
  **Tags:** plugin-development, plugins, php, pagination, xml
  
  > **Comments:**
  > **username_1**: I'm not sure what this has to do with Craft cms. It's more about your XML api and normal php than about Craft. Do you want to know how to create a paginate? There are plenty tutorials. You'll just define an offset and a limit for your XML data and show only records within the range.  
  > **username_0**: Thanks.  Is there anything out of the ordinary PHP pagination code to consider when using the PHP as a Craft cms plugin?  
  
  ---
  
  ## 0 answers
  
  