Skip to content

Instantly share code, notes, and snippets.

@sebastopolys
Last active March 19, 2023 04:06
Show Gist options
  • Save sebastopolys/101dd7c0e1ce3469d52994daf9c287be to your computer and use it in GitHub Desktop.
Save sebastopolys/101dd7c0e1ce3469d52994daf9c287be to your computer and use it in GitHub Desktop.
Alternative switch statement for PHP Class
<?php
namespace Yournamespace;
class GetTemplates{
/*
* dirname(__DIR__)./templates/ is your templates path
* $layout_id is file name
*/
public static function section($section,$layout_id){
$root = file_get_contents(dirname(__DIR__) . '/templates'.'/'.$layout_id.'.html');
$section_act = file_get_contents(__DIR__) . '/templates'.'/'.$layout_id.'.html');
$item_cont = file_get_contents(__DIR__) . '/templates'.'/'.$layout_id.'.html');
$item = file_get_contents(dirname(__DIR__) . '/templates'.'/'.$layout_id.'.html');
if($$section!==null){
return $$section;
}
return "File not found Error";
}
}
// Instantiate e.g.
// returns $section_act
GetTemplates::section('section_act',$layout));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment