Forums | Mahara Community

Developers /
Smarty : add variables in a php file


18 April 2017, 8:54 PM

Hello,

I would like to know if it is possible to add default variables in an external file (ex. mahara\myfolder\lib.php).

I've already created a folder with a lib.php (initialized in init.php) and I want to display a variable in all my smarty files.

How can I do it ?

Thank you ! cool

18 April 2017, 11:09 PM

It works with an include.

 

PHP in myfolder/lib.php :

$smarty = smarty();
$smarty->assign('value', $usrinstval);
$smarty->display('includes/myfile.tpl');

Smarty in includes/myfile.tpl :

{assign var="myvalue" value=$value scope="global"}

But now I have a problem with the function get_field_sql (echo doesn't work).

$usrinstval = get_field_sql('SELECT i.name iname
FROM usr_account_preference ui
INNER JOIN institution i
ON CONCAT(i.theme, \'/\', i.name) = ui.value
WHERE ui.usr = ?', array($USER->id));

Smarty :

I'm in the include and the value is {$myvalue}

I try with $test = "test" and "I'm in the include and the value is {$test}". It works. So I think there is a problem in the variable $usrinstval. With var_dump it works.

Any ideas ?

Thanks !!

19 April 2017, 1:09 AM

PS. In a page template the function works, the problem is the include.

19 April 2017, 8:06 PM

I solved without smarty.


In any case this part is totally useless, it was already declared in the php file : {assign var = "myvalue" value = $ value scope = "global"}

 

Ps. I love my monologues in Mahara's forums.

Kristina Hoeppner's profile picture
Posts: 3632

20 April 2017, 9:03 AM

Hi Antonella,

Great that you could resolve your problem. Sorry, no dev has replied yet. We are head down fixing things for the upcoming release of 17.04 and want to get the release candidate 2 out this week. :-)

Would love to see you at next week's Developer Meeting: https://wiki.mahara.org/wiki/Developer_Area/Developer_Meetings/60

Cheers

Kristina

 

Kristina Hoeppner's profile picture
Posts: 3632

21 April 2017, 7:46 AM

P.S. I postponed the meeting to 4 May as we'll be pretty busy with the release next week, in particular Thursday by the looks of it. :-)

6 results