title: twig: pass variables from view to controller
body: <p><strong>Setup:</strong></p>
  
  <ul>
  <li>Twig 1.13.1</li>
  <li>PHP 5.4.3</li>
  </ul>
  
  <hr>
  
  <p><strong>Problem:</strong></p>
  
  <p>I have 10,000 articles in my DB. I need a way to only allow X amount of stories to display on the page. I know I can limit the number in the controller before i call the template but that number will be different depending on the template that is used. I will have one controller to handles all the articles. I need a way to pass the number from the template to the controller to limit the array. I don't want to pull down all 10,000 articles then use twig "slice" filter/func.</p>
  
  <p>I know in django you can use the below. That will only load the top 3 stories.</p>
  
  <pre><code>{% get_latest_stories 3 sports as story_list %}
  {% for story in story_list %}
      {{ story.title }}
  {% endfor %}
  </code></pre>
  
  <p>Here is my current files.</p>
  
  <p><em>Controller</em></p>
  
  <pre><code>&lt;?php
  $stories = news_stories::getStories("sports",5); //getStories(section,limit);
  ?&gt;
  
  &lt;?=$twig-&gt;render("storyList.html", array('stories' =&gt; $stories))?&gt;
  </code></pre>
  
  <p><em>View/Template</em></p>
  
  <pre><code>{% for story in story_list %}
      {{ story.title }}
  {% endfor %}
  </code></pre>
  
  <hr>
  
  <p><strong>Summary</strong></p>
  
  <p>I would like a way to pass a number from the template to the controller so that i can limit the about of rows returned from the DB</p>