title: Twig tag with some PHP logic within
body: <p>I'm new in using Twig, but I have a good grab on django templates.</p>
  
  <p>My site is not a Symfony project, but I use Twig as a template language.</p>
  
  <p>What I need is to display a "latest news" block on every page of my site. Putting the logic into an every controller is really not an option.</p>
  
  <p>From my django experience, I was hoping to create a custom tag and render it in my base template. Django has so-called custom "<a href="https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags-inclusion-tags" rel="nofollow">inclusion tags</a>". A tag that performs some python logic and renders its results via another template.</p>
  
  <p>I read about custom tags in Twig. And I successfully created a parser for my shiny new <code>{% latest_news 5 %}</code> tag. But how to execute PHP script in my <code>LatestNews_Node</code>? I read some Twig source code. They use <code>$compiler-&gt;write(...)</code> to execute PHP code. Is that the only way to execute custom PHP in tag?</p>
  
  <p>And how to render it via another template and return result at the end?</p>
  
  <p>I tried to look for a working example with no result</p>