How To Pass Data To A Custom Template Block

Hi,

I am making a block to use as a client-service block in the homepage. I found some information in tutorials and forum. So far so good. I want the company's phonenumber in it. I found this in the _settings_objects database table. I managed to get a query running. But I didn't get it to run with a dynamic condition. For later use, I would like it to pass dynamicly. How to do this? What am I missing?

So far I have this:
\app\addons\my_changes\func.php
function fn_get_service_data($name='company_phone')
{
//$company_data = db_get_row("SELECT * FROM ?:settings_objects WHERE name = ?s", $name);
$company_data = db_get_row("SELECT * FROM ?:settings_objects WHERE name = ?s", 'company_phone');
return $company_data;
}

And this:
\design\themes\nrp\templates\addons\my_changes\blocks\static_templates\service_box.tpl
{$data = $param1|fn_get_servi ce_data:$param2}
{$data.value}

And when do I have to use my_changes and when do I need to make a new add_on? What is the difference?

Tygh::$app[‘view’]->assign(‘variable_name’, $value);

And when do I have to use my_changes and when do I need to make a new add_on? What is the difference?

There is no difference, you can use my_changes add-on for your modification. But, in my opinion, if you have a lot of changes, it is better to create new add-ons. If you put all the changes in one add-on, you can not disable them one by one, you will have to disable them all (the whole add-on). So if you create different add-ons for every feature you would like to have, you can easily manage them.

Tygh::$app['view']->assign('variable_name', $value);

And in which file would I put this? And before of after which part?

Depends on which controller your block is following in. You can use an init.post.php controller.

You can just use the following variable in your SMARTY block:

{$settings.Company.company_phone}

You can just use the following variable in your SMARTY block:

{$settings.Company.company_phone}

Just that easy! It works! Thanks!

You are welcome! :)