Skip to content

Commit

Permalink
templates functions
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardBock committed Oct 29, 2020
1 parent 2542f66 commit 9b5359c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 39 deletions.
2 changes: 1 addition & 1 deletion classes/Model/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Box extends _Base {

/**
* Reference to the Grid itself
* @var Storage
* @var Grid
*/
public $grid;

Expand Down
99 changes: 62 additions & 37 deletions classes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,94 @@
class Template implements iTemplate {

private static $templatesPaths = [];
public static function paths(){

/**
* @return string[]
*/
public static function paths() {
return self::$templatesPaths;
}
public function addTemplatesPath($absolutePath){

/**
* @param string $absolutePath
*/
public function addPath( string $absolutePath ) {
self::$templatesPaths[] = $absolutePath;
}

/**
* @param string $filename for example post_content.tpl.php
*
* @return false|string
*/
public static function getPath( string $filename ) {
foreach ( static::$templatesPaths as $path ) {
$template_path = trailingslashit( $path );
if ( file_exists( $template_path . $filename ) ) {
return $template_path . $filename;
}
}

return false;
}

/**
* @param grid_grid $grid
*
* @return string
*/
public static function grid( grid_grid $grid) : string{
foreach (self::$templatesPaths as $templatesPath) {
$template_path = rtrim($templatesPath.'/grid.tpl.php', "/");
if( file_exists($template_path) ){
public static function grid( grid_grid $grid ): string {
foreach ( self::$templatesPaths as $templatesPath ) {
$template_path = rtrim( $templatesPath . '/grid.tpl.php', "/" );
if ( file_exists( $template_path ) ) {
return $template_path;
}
}

return dirname( __FILE__ ) . '/../templates/components/grid.tpl.php';
}

/**
* @param grid_container $container
*
* @return string
*/
public static function container( grid_container $container): string{

foreach (self::$templatesPaths as $templatesPath)
{
$template_path = rtrim($templatesPath."/grid-container.tpl.php", "/");
if( file_exists($template_path) ){
/**
* @param grid_container $container
*
* @return string
*/
public static function container( grid_container $container ): string {

foreach ( self::$templatesPaths as $templatesPath ) {
$template_path = rtrim( $templatesPath . "/grid-container.tpl.php", "/" );
if ( file_exists( $template_path ) ) {
return $template_path;
}
}

return dirname(__FILE__).'/../templates/components/grid-container.tpl.php';
return dirname( __FILE__ ) . '/../templates/components/grid-container.tpl.php';
}

/**
* @param grid_slot $slot
*
* @return string
*/
public static function slot( grid_slot $slot): string{
/**
* @param grid_slot $slot
*
* @return string
*/
public static function slot( grid_slot $slot ): string {

foreach (self::$templatesPaths as $templatesPath) {
$template_path = rtrim($templatesPath.'/grid-slot.tpl.php', "/");
if( file_exists($template_path) ){
foreach ( self::$templatesPaths as $templatesPath ) {
$template_path = rtrim( $templatesPath . '/grid-slot.tpl.php', "/" );
if ( file_exists( $template_path ) ) {
return $template_path;
}
}

return dirname( __FILE__ ) . '/../templates/components/grid-slot.tpl.php';
}

/**
* @param grid_box $box
* @param bool $editmode
*
* @return string
*/
public static function box( grid_box $box, bool $editmode): string{
/**
* @param grid_box $box
* @param bool $editmode
*
* @return string
*/
public static function box( grid_box $box, bool $editmode ): string {
$typechecks = array();
$class = get_class( $box );
$typechecks[] = preg_replace( "/(?:grid_(.*)_box|grid_(box))/u", "$1$2", $class );
Expand Down Expand Up @@ -110,10 +134,11 @@ public static function box( grid_box $box, bool $editmode): string{
}
}

if($editmode){
return dirname(__FILE__).'/../templates/components/grid-box-editmode.tpl.php';
if ( $editmode ) {
return dirname( __FILE__ ) . '/../templates/components/grid-box-editmode.tpl.php';
}
return dirname(__FILE__).'/../templates/components/grid-box.tpl.php';

return dirname( __FILE__ ) . '/../templates/components/grid-box.tpl.php';
}

}
2 changes: 1 addition & 1 deletion components/grid_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function render($editmode)
}

ob_start();
include $templatePath = API::template()::grid($this);
include API::template()::grid($this);
$output=ob_get_contents();
ob_end_clean();

Expand Down

0 comments on commit 9b5359c

Please sign in to comment.