Quantcast
Channel: Discussions - T3 - Joomla Template Framework
Viewing all articles
Browse latest Browse all 3483

How to make PHP variables in blocks accessible from template?

$
0
0
I have a lot of backend PHP code that I am using on a template I defined, so I want to hide away most of it in a block. But when I do this, the variables I declared and assigned in the block are not accessible in the template file, even though the template file is properly calling in the block.

As as an example, let's say I have a very basic template file being used, home1.php. home1.php includes this code:

In the blocks folder, I have a file called setup.php. In this file, let's say I just have some very simple PHP code, like
$x = 5;
But then in home1.php, if I do this:
echo $x;
It won't work, because home1.php doesn't have access to the variable $x from setup.php. The actual code is much more complex of course, but if I can figure out how to access PHP variables in blocks from the templates that call them, that would be very helpful. Or, maybe there is another way I should be doing this? I just don't like having 300 lines of PHP code at the beginning of my template file, but I don't see a way around it unless I can put it in a block. Do I just need to use the PHP require function to call an outside PHP file or something?

Thank you for any help.

Viewing all articles
Browse latest Browse all 3483

Trending Articles