0

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.

asprin
  • 9,579
  • 12
  • 66
  • 119
  • https://stackoverflow.com/a/18949864/3859027 i've used this as some kind of reference in the past – Kevin Sep 23 '19 at 04:25
  • or you can just use a complete mvc framework if it suits your needs like codeigniter or laravel – Kevin Sep 23 '19 at 04:28
  • @Kevin Not entirely sure if I can follow that approach given that Simple Machine Forums does not use OOP – asprin Sep 23 '19 at 04:28
  • i think you'd still be able to apply the linked answer above as it just requires inclusion of few files around. or you could use persistent storage like sessions – Kevin Sep 23 '19 at 04:30

0 Answers0