S
S
Sergey Goryachev2016-10-13 00:27:26
CMS
Sergey Goryachev, 2016-10-13 00:27:26

How to output PHP code to another Joomla module file?

The question, in general, is probably simple, but I can’t figure out how to do it right.
There are two files - helper.php and default.php.
Helper, this is crap in which the connection to the database is processed.
And a default is an output in a template of the received data.
With the receipt of data, everything is fine, I receive.

<?php
defined('_JEXEC') or die;
class modCarouselHelper
{
public static function getCarousel()
{
$db = JFactory::getDbo();
$query = 'SELECT * FROM #__carousel';
$db->setQuery($query);
$carousels = $db->loadObjectList();
foreach ( $carousels as $carousel ) {
echo <<<HTML
<div>
<img src="{$carousel->slider_image}" alt="{$carousel->alt_image}">
</div>
HTML;
}
}
}

It all works and the data is displayed. But the output must be done through default.php, and not like I have now through echo :)))) This is how I output it for testing)
The template file itself also connects normally.
But I can’t transfer data from the helper to the template.
How to implement it correctly?
Simply put, I need to parse this $carousels variable and transfer it to another file.
PS: The explainer from me is so-so.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2016-10-13
@webirus

если default.php это шаблон, то похоже так:

...
foreach ( $carousels as $carousel ) {
    include dirname(__FILE__).'/default.php';
}
...

ну, а все что было echo перенести в default.php:
<div>
<img src="<?=$carousel->slider_image?>" alt="<?=$carousel->alt_image?>">
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question