(Good or bad?) Calling a Function in Template File which returns a theme() Function value I have a function which get some values from a Term, calculates something and at the end of my function, there is a statement like this:

return theme('foo', array('bar' =&gt; 1);


This function is in a self-written module. In the same module, I've got a template file.

Now my question: is it good or bad Practice to call the function which one I describe above in the template file? I know that I could calculate all this before calling the template file, but with my solution, the could would be more readable.

Thank you in avantage for inputs.
If you are asking about calling theme() from inside a template file, that is possible, but it is rarely done: Out of 214 calls to theme() done from Drupal (and the Views module) only two calls are done from inside s template file. 

This is the code used in the default implementation of page.tpl.php; similar code is present in the implementation of page.tpl.php for the Bartik theme.

&lt;?php if ($main_menu || $secondary_menu): ?&gt;
  &lt;div id="navigation"&gt;&lt;div class="section"&gt;
    &lt;?php print theme('links__system_main_menu', array('links' =&gt; $main_menu, 'attributes' =&gt; array('id' =&gt; 'main-menu', 'class' =&gt; array('links', 'inline', 'clearfix')), 'heading' =&gt; t('Main menu'))); ?&gt;
    &lt;?php print theme('links__system_secondary_menu', array('links' =&gt; $secondary_menu, 'attributes' =&gt; array('id' =&gt; 'secondary-menu', 'class' =&gt; array('links', 'inline', 'clearfix')), 'heading' =&gt; t('Secondary menu'))); ?&gt;
  &lt;/div&gt;&lt;/div&gt; &lt;!-- /.section, /#navigation --&gt;
&lt;?php endif; ?&gt; 


What you should do is initializing a variable in the preprocess function for the template file, and use that variable in the template file.  

Truly, you should not put logic code in your template file; this means that, for example, code similar to the following one should not be used in a template file.

&lt;?php if ($condition1): ?&gt;
  &lt;?php print theme('theme_1', $values1); ?&gt;
&lt;?php elseif ($condition2): ?&gt;
  &lt;?php print theme('theme_2', $values2); ?&gt;
&lt;?php elseif ($condition3): ?&gt;
  &lt;?php print theme('theme_3', $values3); ?&gt;
&lt;?php endif; ?&gt;


If the code is similar to the following one, then it would be more acceptable, but I would still think of possible future versions of the code, and prefer using a variable in the preprocess function.

  &lt;?php print theme('theme_1', $values1); ?&gt;
  &lt;?php print theme('theme_2', $values2); ?&gt;
  &lt;?php print theme('theme_3', $values3); ?&gt;