Xiomera
Member
I would like to display an additional value for every thread in the thread view and the thread list (forum view), which i calculate with an php function.
My problem: what is the best way to make a variable useable in an tempalte from an php file? And How?
I found 2 solutions. The callback tag in template (which calls the php function) or the possiblity to add the variable to an object like $forum (in my case $thread) in php.
What solution is more efficient and advisable in my case?
The callback tag worked for me just fine. Although I am not sure if this is the perfect solution (cuz I have to call it every time I need the varaible - can't assign it to a local variable in the template).
For the second solution I tryed to follow this thread, but there is no code event listener for a thread (or something suitable for my problem).
Is there a way to add a variable to the $thread object via php without the listener? I am thinking about a callback which adds the variable to $thread. in this case I only have to call it once and can then use it with the $thread object in the template.
Or is there a better solution?
Ps: I am takling about adding an variable to $thread, that can be accessed like this
Stricktly speaking which solution is more suitable for me? In case it is the second one a basic code example would be very needed.
Thank you for your time and help!
-Xiomera
My problem: what is the best way to make a variable useable in an tempalte from an php file? And How?
I found 2 solutions. The callback tag in template (which calls the php function) or the possiblity to add the variable to an object like $forum (in my case $thread) in php.
What solution is more efficient and advisable in my case?
The callback tag worked for me just fine. Although I am not sure if this is the perfect solution (cuz I have to call it every time I need the varaible - can't assign it to a local variable in the template).
HTML:
<xf:callback class="\XF\CustomFiles\MyFile" method="getFormatedScore" param="$thread"></xf:callback>
For the second solution I tryed to follow this thread, but there is no code event listener for a thread (or something suitable for my problem).
Is there a way to add a variable to the $thread object via php without the listener? I am thinking about a callback which adds the variable to $thread. in this case I only have to call it once and can then use it with the $thread object in the template.
Or is there a better solution?
Ps: I am takling about adding an variable to $thread, that can be accessed like this
HTML:
<strong>{$thread.myCustomScore}</strong>
Stricktly speaking which solution is more suitable for me? In case it is the second one a basic code example would be very needed.
Thank you for your time and help!
-Xiomera