: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace NetworkPosts\Components;
//use Twig\Loader\FilesystemLoader;
class NetsPostsTemplateRenderer {
private static $instance;
private static $twig = null;
private static $views_path;
protected function __construct( $views_path ) {
self::$views_path = $views_path;
//$loader = new \Twig_Loader_Filesystem( self::$views_path );
//self::$twig = new \Twig_Environment( $loader );
public static function render( $template_relative_path, $data = [] ) {
$full_path = self::$views_path . $template_relative_path;
if ( file_exists( $full_path ) ) {
return self::render_template( $full_path, $data );
//throw new RuntimeException( 'Class ' . self::class . ' is not initialized.' );
private static function render_template( $template, $data ) {
$h = fopen( $template, 'r+' );
while ( ( $line = fgets( $h, 4096 ) ) !== false ) {
foreach ( $data as $key => $value ) {
$line = str_replace( "%${key}%", $value, $line );
public static function init( $views_path ) {
self::$instance = new NetsPostsTemplateRenderer( $views_path );