I've seen many other posts regarding using PHP code in pages, but they either involve simple, 3-line scripts that can easily be translated into Twig or whatever, or the thread gets bumped with other people asking similar questions with no answers. So, here I am.
I need to have the following script run on a page in OctoberCMS AS IS:
$files = array();
$dir = opendir('/public/uploads/uploads/');
while(false != ($file = readdir($dir))) {
if(($file != ".") and ($file != "..") and ($file != "index.php")) {
$files[] = $file; // put in array.
}
}
closedir($dir);
natsort($files); // sort
foreach($files as $file) {
$name = preg_replace('/\\.[^.\\s]{3}$/', '', $file);
$fname = str_replace("_", " ", $name);
$this["gallery"] = "<div class='portfolio-item'>
<div class='portfolio-item-wm'>
<span></span>
<img src='/public/uploads/uploads/$file'>
</div>
<h4>$fname</h4>
</div>";
}
I don't want to translate any of it into Twig, but I know that I might need to reference the script on the page using {{ varaible }} or something.
Hopefully someone can help me :/
Last updated