I have an external php function that prints out a formatted calendar for any given month / year. I'd like to incorporate this into my smarty template, but it keeps printing it out above everything else on the page.

My index.php file contains the following:

/* calls the function */
$calendar = pc_calendar($month, $year);

/* assigns it */
$smarty->assign("calendar", $calendar);

My smarty template contains the following:

{include file="header.tpl"}
{include file="navigation.tpl" page_title="Example"}
<div id="content">
/* Here's where I want the calendar to go */
{$calendar}
</div>
{include file="footer.tpl"}

But, it keeps printing out the table above the header file. If I do the following, it print out where I want it to:

{include file="header.tpl"}
{include file="navigation.tpl" page_title="Example"}
<div id="content">
/* Here's where I want the calendar to go */
{php}
pc_calendar($month, $year);
{/php}
</div>
{include file="footer.tpl"}

But, I was kinda hoping I could avoid using php code directly in my tpl file, plus, I'd like to understand the problem. Any ideas?

    Your problem is due to your function printing the contents when called.

    Change it to return the data.

    i.e.

    //from
    function something(){
      echo 'data';
    }
    
    //to
    function something(){
      $data = 'something';  
    return $data; }
      Write a Reply...