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

Configurable templates #1316

Open
wants to merge 2 commits into
base: next
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/Collections/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ public function collection($name = null) {
// get field templates
$templates = [];

foreach ($this->app->helper('fs')->ls('*.php', 'collections:fields-templates') as $file) {
$templatesPath = 'collections:fields-templates';
if ($customTemplatesPath = $this->path('#config:collections/templates')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not allow both? collect the paths in an array and then do a loop over the folders

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional to avoid naming conflicts and to have the ability to override the default template(s). If I choose to use custom templates I can still copy the core collection template to my template folder.

$templatesPath = $customTemplatesPath;
}

foreach ($this->app->helper('fs')->ls('*.php', $templatesPath) as $file) {
$templates[] = include($file->getRealPath());
}

Expand Down
15 changes: 14 additions & 1 deletion modules/Singletons/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public function singleton($name = null) {
$this->app->helper('admin')->lockResourceId($singleton['_id']);
}

// get field templates
$templates = [];

if ($templatesPath = $this->path('#config:singletons/templates')) {
foreach ($this->app->helper('fs')->ls('*.php', $templatesPath) as $file) {
$templates[] = include($file->getRealPath());
}
}

foreach ($this->app->module('singletons')->singletons() as $sin) {
$templates[] = $sin;
}

// acl groups
$aclgroups = [];

Expand All @@ -77,7 +90,7 @@ public function singleton($name = null) {
if (!$superAdmin) $aclgroups[] = $group;
}

return $this->render('singletons:views/singleton.php', compact('singleton', 'aclgroups'));
return $this->render('singletons:views/singleton.php', compact('singleton', 'aclgroups', 'templates'));
}

public function form($name = null) {
Expand Down
5 changes: 3 additions & 2 deletions modules/Singletons/views/singleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

<div class="uk-margin-large-top" show="{ view==='fields' }">

<cp-fieldsmanager bind="singleton.fields"></cp-fieldsmanager>
<cp-fieldsmanager bind="singleton.fields" listoption="true" templates="{ templates }"></cp-fieldsmanager>

</div>

Expand Down Expand Up @@ -162,7 +162,8 @@
this.view = 'fields';

this.singleton = {{ json_encode($singleton) }};
this.aclgroups = {{ json_encode($aclgroups) }};
this.templates = {{ json_encode($templates) }};
this.aclgroups = {{ json_encode($aclgroups) }};

if (!this.singleton.acl) {
this.singleton.acl = {};
Expand Down