Hi
i am currently trying to set an Array via Custom Code as var. when i print out the Array its ok but how can i access this var from another view?
Event:
Option to return VAR is set to ON
i am currently trying to set an Array via Custom Code as var. when i print out the Array its ok but how can i access this var from another view?
Event:
<h1>Select Team</h1>fn clear_years_teams_result:
{fn:read_years_teams} <!-- Gets all Teams for year x,y,z (also duplicated values if a team played in season x&z) -->
{fn:clear_years_teams_result} <!-- My Custom Function which takes the read_years_teams var and check for duplicates (code below)-->
{view:repeater_teams_in_years} <!-- Repeater which will create a Card for each team based on the return of fn clear_years_teams-->
{debug:}
Option to return VAR is set to ON
<?phpIn my Repeater i have the "data provider" Field but when i enter there {var:clear_years_teams_result} nothing happens - also debug does not show anything on the page itself?
$years_teams = $this->get("read_years_teams");
$teamlist = [ ];[li];
foreach($years_teams as $team){
if(!in_array($team['Team'], $teamlist)){
$teamlist[ ] = $team['Team'];[/li]
}
}
/* Debug:
foreach($teamlist as $element){
echo "".$element["id"]." - ".$element["name"]."<br />";
}
*/
[br]return $teamlist; // returns an Array of Associative Arrays[br][br]?>
OK got it
If you want to return a Value from a Custom Code Element you have to use this Syntax:
and for sure the "VAR Option Only Option is set to YES"
[pre]<?php
$years_teams = $this->get("read_years_teams");
$teamlist = [];
foreach($years_teams as $team){
if(!in_array($team['Team'], $teamlist)){[br] $teamlist[]=$team['Team'];[br] }[br]}[br]$this->data['teamlist'] = $teamlist;[br]?>[/pre]
This returns (in my case) the array $teamlist into the data array of the page:
Hope that helps also someone else...
kind regards
Proximate
If you want to return a Value from a Custom Code Element you have to use this Syntax:
$this->data['teamlist'] = $teamlist;no return statement is needed in my case my custom Code Block looks like that:
and for sure the "VAR Option Only Option is set to YES"
[pre]<?php
$years_teams = $this->get("read_years_teams");
$teamlist = [];
foreach($years_teams as $team){
if(!in_array($team['Team'], $teamlist)){[br] $teamlist[]=$team['Team'];[br] }[br]}[br]$this->data['teamlist'] = $teamlist;[br]?>[/pre]
This returns (in my case) the array $teamlist into the data array of the page:
ArrayAnd is now accessible via:
(
[conn] => safsc
[target] => table
[event] => safsc_table_selectTeams
...
[option] => com_chronoconnectivity6
[view] => connection
[teamlist] => Array
(
[0] => Array
(
[id] => 1
[name] => Calanda Broncos
[color] => #be1a1b[br] [logo] => broncos.png[br] [web] => http://www.calandabroncos.ch[br] )[br]...
{data:teamlist}
Hope that helps also someone else...
kind regards
Proximate
{var.set:name$data}
OR
$this->set("name", data);
Then available under {var:name}
OR
$this->set("name", data);
Then available under {var:name}
Or set the custom code block to return var, and whatever you echo or print there is stored in {var:code_block_name}
Strange - in my tests the code Above failed:
<?phpEdit:
$my_php_var = 'Foo';
{var.set:my_var_name$my_php_var} // Error: syntax error, unexpected 'var' (T_VAR)
?>
$this->set('my_var_name', $my_php_var) // Works when called after with {var:my_var_name} but is not shown in debug (?)
Yes you can't use shortcodes in PHP code. Close off the PHP tag, use your shortcode, open the PHP tag again - or just use the PHP code you've used.
This topic is locked and no more replies can be posted.