Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When looking for template, don't just pick first one, but test if it is a template file. #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/asset-types/page.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ static function template_type($template_file) {

static function template_name($file_path) {
$txts = array_keys(Helpers::list_files($file_path, '/\.txt$/'));
# return first matched .txt file
return (!empty($txts)) ? preg_replace('/\.txt$/', '', $txts[0]) : false;
$template = '';
#Walk trough txts and find template
foreach ($txts as $txt) {
$file = preg_replace('/\.txt$/', '', $txt);
if (Page::template_file($file) != false) {
$template = $file;
break;
}
}
return (!empty($template)) ? $template : false;
}

static function template_file($template_name) {
Expand Down
2 changes: 1 addition & 1 deletion app/page-data.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static function create_collections($page) {
# $root
$page->root = Helpers::list_files('./content', '/^\d+?\./', true);
# $parent
$parent_path = self::get_parent($page->file_path, $page->url_path);
$parent_path = self::get_parent($page->file_path, $page->url_path);
$page->parent = $parent_path;
# $parents
$page->parents = self::get_parents($page->file_path, $page->url_path);
Expand Down