Use actual twig variables for the page body

Replaces <!--AntCMS-Body--> with {{ AntCMSBody | raw }}
This commit is contained in:
Belle Aerni 2023-01-25 21:32:38 -08:00
parent e2ca10d51d
commit e1667b6374
4 changed files with 16 additions and 23 deletions

View file

@ -23,8 +23,6 @@ class AntCMS
$this->renderException("404");
}
$markdown = AntMarkdown::renderMarkdown($content['content']);
$pageTemplate = $this->getPageLayout(null, $page);
$params = array(
@ -32,8 +30,8 @@ class AntCMS
'AntCMSDescription' => $content['description'],
'AntCMSAuthor' => $content['author'],
'AntCMSKeywords' => $content['keywords'],
'AntCMSBody' => AntMarkdown::renderMarkdown($content['content']),
);
$pageTemplate = str_replace('<!--AntCMS-Body-->', $markdown, $pageTemplate);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
$end_time = microtime(true);
@ -78,8 +76,8 @@ class AntCMS
$exceptionString = $exceptionString . " (Code $exceptionCode)";
$pageTemplate = self::getPageLayout();
$pageTemplate = str_replace('<!--AntCMS-Title-->', 'An error ocurred', $pageTemplate);
$pageTemplate = str_replace('<!--AntCMS-Body-->', '<h1>An error ocurred</h1><p>' . $exceptionString . '</p>', $pageTemplate);
$pageTemplate = str_replace('{{ AntCMSTitle }}', 'An error ocurred', $pageTemplate);
$pageTemplate = str_replace('{{ AntCMSBody | raw }} ', '<h1>An error ocurred</h1><p>' . $exceptionString . '</p>', $pageTemplate);
http_response_code($httpCode);
echo $pageTemplate;
@ -150,7 +148,7 @@ class AntCMS
</head>
<body>
<p>AntCMS had an error when fetching the page template, please contact the site administrator.</p>
<!--AntCMS-Body-->
{{ AntCMSBody | raw }}
</body>
</html>';
} else {

View file

@ -38,20 +38,19 @@ class AdminPlugin extends AntPlugin
$this->managePages($route);
default:
$HTMLTemplate = "<h1>AntCMS Admin Plugin</h1>\n";
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/config/'>AntCMS Configuration</a><br>\n";
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/pages/'>Page management</a><br>\n";
$params = array(
'AntCMSTitle' => 'AntCMS Admin Dashboard',
'AntCMSDescription' => 'The AntCMS admin dashboard',
'AntCMSAuthor' => 'AntCMS',
'AntCMSKeywords' => '',
'AntCMSBody' => $HTMLTemplate,
);
$HTMLTemplate = "<h1>AntCMS Admin Plugin</h1>\n";
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/config/'>AntCMS Configuration</a><br>\n";
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/pages/'>Page management</a><br>\n";
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
echo $pageTemplate;
echo AntTwig::renderWithTiwg($pageTemplate, $params);
break;
}
}
@ -116,10 +115,8 @@ class AdminPlugin extends AntPlugin
$HTMLTemplate .= "</ul>\n";
}
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
echo $pageTemplate;
$params['AntCMSBody'] = $HTMLTemplate;
echo AntTwig::renderWithTiwg($pageTemplate, $params);
exit;
}
@ -247,10 +244,8 @@ class AdminPlugin extends AntPlugin
$HTMLTemplate .= "</ul>\n";
}
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
echo $pageTemplate;
$params['AntCMSBody'] = $HTMLTemplate;
echo AntTwig::renderWithTiwg($pageTemplate, $params);
exit;
}

View file

@ -38,7 +38,7 @@
<div class="container">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10"><!--AntCMS-Body--></div>
<div class="col-md-10">{{ AntCMSBody | raw }}</div>
<div class="col-md-1"></div>
</div>
</div>

View file

@ -44,7 +44,7 @@
<div class="container mx-auto my-4">
<div class="flex flex-wrap -mx-4">
<div class="w-1/12"></div>
<div class="w-10/12 prose dark:prose-invert max-w-none"><!--AntCMS-Body--></div>
<div class="w-10/12 prose dark:prose-invert max-w-none">{{ AntCMSBody | raw }}</div>
<div class="w-1/12"></div>
</div>
</div>