• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

help with pulling function in twig

hiquezerah

New Member
Joined
Dec 24, 2020
Messages
11
Reaction score
1
I am using myacc

hello guys, I'm looking for a way to pull a function to the twig file, I'm making some changes in my character view.
I'm wanting to pull a value from a storage that the player has for the twig.
Example:
View attachment 68432
I managed to add this function in php and it worked. But I'm not able to use it in a twig, could someone help me?

Function.php
function reborn(){
global $db, $config;

$resposta = $db->query('SELECT * FROM player_storage WHERE KEY = 30024;');
return $resposta;
}
$rebornado = 0;
foreach(reborn() as $rbStorage){
if ($rbStorage['player_id'] == $listPlayer['id']){
echo'<td>Rebornado level<br>'. $rbStorage['value'] . '</td>';
$rebornado = 1;
break;
}
}
if ($rebornado == 0)
echo'<td>Não rebornado</td>';
$rebornado = 0;
using these 2 codes I managed to add to php.
But now I'm needing to add to the twig file.
Example:
View attachment 68433
could someone tell me how can i call the "reborn" function inside character.html.twig?

@slaw
 
There are 2 options:

1) you pass your function as argument from php to twig

in characters.php

after:
Code:
$twig->display('characters.html.twig', array(
   'outfit' => isset($outfit) ? $outfit : null,

add in new line:
Code:
   'reborn' => reborn(),

Then in twig you can use:
Code:
{% for value in reborn %}
<td>Rebornado level<br>{{ value.value }}</td>
{% endfor %}

2) second option is that you call the function directly in twig

in this scenario you first need to add the function to twig

first add this into system/twig.php
Code:
$function = new TwigFunction('reborn', function () {
   return reborn();
});

Then in twig you can do like this:
Code:
{% for value in reborn() %}
<td>Rebornado level<br>{{ value.value }}</td>
{% endfor %}

Notice the difference in twig in reborn vs reborn()

Hope I didn't explain too complicated.
 
There are 2 options:

1) you pass your function as argument from php to twig

in characters.php

after:
Code:
$twig->display('characters.html.twig', array(
   'outfit' => isset($outfit) ? $outfit : null,

add in new line:
Code:
   'reborn' => reborn(),

Then in twig you can use:
Code:
{% for value in reborn %}
<td>Rebornado level<br>{{ value.value }}</td>
{% endfor %}

2) second option is that you call the function directly in twig

in this scenario you first need to add the function to twig

first add this into system/twig.php
Code:
$function = new TwigFunction('reborn', function () {
   return reborn();
});

Then in twig you can do like this:
Code:
{% for value in reborn() %}
<td>Rebornado level<br>{{ value.value }}</td>
{% endfor %}

Notice the difference in twig in reborn vs reborn()

Hope I didn't explain too complicated.
@slaw
Hi bro, i am test now
it worked bro, but I think it's returning the reborn of all players, I wanted you to get only the reborn of the player I'm going to look at in the character, you know?
would have to take the Player ID, right?
do i need to modify something in the function? Could you help me, please?
1654790088950.png
{% for value in player.reborn %} I am test now < I did not succeed
<td class="rb">Rebornado level<br>{{ value.value }}</td>
{% endfor %}
 
Last edited:
Back
Top