How to pass data from sources to template function?

89 views Asked by At

If I make a SELECT query from the sources file (sources/Example.php), then how would I pass the returned data to the template function being called?

sources/Example.php

function DoSomething()
{
    global $context;
    loadTemplate('Example');
    $data = <get some data by querying the database>
    .
    .
    .
    .
    .

    $context['sub_template'] = 'listData';

    // now pass this $data to the listData function
}

themes/default/Example.template.php

function template_listData()
{
    // access $data here
}

One thing that I can think of is creating a key in the $context array and assigning the data to that key. But I was wondering if there is a better/alternate approach to this.

0

There are 0 answers