Include a file inside block template (view.php)

Hi,
Is there a recommended way to include an external file from a block template (view.php).
The php include(‘view_component_1.php’) works just fine, but I thought maybe there was a better and more secure way of doing such a thing inside the CMS.

Hi.

It depends where the file is. If you are at liberty to put it wherever you want, the best way would be to put it in the application\elements folder or in a package elements folder if you’re using a package.

Then do

use Concrete\Core\View\View;

View::element('name_of_file_without_extension', ['a_variable_name' => $variable_value], 'package_handle_if_any');

Using it like that allows you to pass your files some variables it might need. In this example, within the file you’ll have access to $a_variable_name.