Is there a way to the same detail page template for different sections?

2 posts by 1 authors in: Forums > CMS Builder
Last Post: 10 hours ago   (RSS)

Ok, i think i have a working solution so I am sharing in case it's helpful to someone else:

<?php
  header('Content-type: text/html; charset=utf-8');
  include_once("../cmsb/lib/viewer_functions.php");

  // get the URI and trim leading and trailing slashes
  $uri = trim($_SERVER['REQUEST_URI'], '/');

  // lookup the URI in the permalinks table to find the corresponding section
  $section = mysql_get('cmsb__permalinks', null, [
    'permalink' => $uri,
    'old'       => '0'
  ]);

  // get the tablename for the section
  if ($section) {
    $tableName = $section['tableName'];
	
    // and then load the page
    list($page, $pageMetaData) = getRecords(array(
      'tableName'   => $tableName,
      'where'       => whereRecordNumberInUrl(0),
      'loadUploads' => true,
      'allowSearch' => false,
      'limit'       => '1',
    ));
    $page = @$page[0]; // get first record
    if (!$page) { 
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: /"); 
      exit;
    }
  }

?>