Skip to content

Commit

Permalink
Merge pull request craftcms#11840 from craftcms/feature/twig-paths
Browse files Browse the repository at this point in the history
`.twig` template paths
  • Loading branch information
brandonkelly authored Aug 30, 2022
2 parents 99b4401 + a4cc8c2 commit 1e5d53d
Show file tree
Hide file tree
Showing 85 changed files with 163 additions and 162 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- Element query date params now support passing `today`, `tomorrow`, and `yesterday`. ([#10485](https://github.com/craftcms/cms/issues/10485))
- Element queries now support passing ambiguous column names (e.g. `dateCreated`) and field handles into `select()`. ([#11790](https://github.com/craftcms/cms/pull/11790), [#11800](https://github.com/craftcms/cms/pull/11800))
- `{% cache %}` tags now store any HTML registered with `{% html %}` tags. ([#11811](https://github.com/craftcms/cms/discussions/11811))
- Control panel `.twig` templates are now prioritized over `.html`. ([#11809](https://github.com/craftcms/cms/discussions/11809), [#11840](https://github.com/craftcms/cms/pull/11840))
- `craft\helpers\Component::iconSvg()` now namespaces the SVG contents, and adds `aria-hidden="true"`. ([#11703](https://github.com/craftcms/cms/pull/11703))
- `craft\services\Search::EVENT_BEFORE_INDEX_KEYWORDS` is now cancellable by setting `$event->isValid` to `false`. ([#11705](https://github.com/craftcms/cms/discussions/11705))
- `checkboxSelect` inputs without `showAllOption: true` now post an empty value if no options were selected. ([#11748](https://github.com/craftcms/cms/issues/11748))
Expand Down
2 changes: 1 addition & 1 deletion src/assetpreviews/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getPreviewHtml(array $variables = []): string
]);
}

return Craft::$app->getView()->renderTemplate('assets/_previews/image',
return Craft::$app->getView()->renderTemplate('assets/_previews/image.twig',
array_merge([
'asset' => $this->asset,
'url' => $url,
Expand Down
2 changes: 1 addition & 1 deletion src/assetpreviews/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getPreviewHtml(array $variables = []): string
FileHelper::unlink($localCopy);
$language = $this->asset->kind === Asset::KIND_HTML ? 'markup' : $this->asset->kind;

return Craft::$app->getView()->renderTemplate('assets/_previews/text',
return Craft::$app->getView()->renderTemplate('assets/_previews/text.twig',
array_merge([
'asset' => $this->asset,
'language' => $language,
Expand Down
2 changes: 1 addition & 1 deletion src/assetpreviews/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getPreviewHtml(array $variables = []): string
throw new NotSupportedException('Preview not supported.');
}

return Craft::$app->getView()->renderTemplate('assets/_previews/video',
return Craft::$app->getView()->renderTemplate('assets/_previews/video.twig',
array_merge([
'asset' => $this->asset,
'url' => $url,
Expand Down
2 changes: 1 addition & 1 deletion src/base/MissingComponentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getPlaceholderHtml(): string
}
}

return Craft::$app->getView()->renderTemplate('_special/missing-component', compact(
return Craft::$app->getView()->renderTemplate('_special/missing-component.twig', compact(
'error',
'showPlugin',
'isComposerInstalled',
Expand Down
2 changes: 1 addition & 1 deletion src/base/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function getSettingsResponse(): mixed
/** @var Controller $controller */
$controller = Craft::$app->controller;

return $controller->renderTemplate('settings/plugins/_settings', [
return $controller->renderTemplate('settings/plugins/_settings.twig', [
'plugin' => $this,
'settingsHtml' => $settingsHtml,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public function actionImageEditor(): Response

$focal = $asset->getHasFocalPoint() ? $asset->getFocalPoint() : null;

$html = $this->getView()->renderTemplate('_special/image_editor');
$html = $this->getView()->renderTemplate('_special/image_editor.twig');

return $this->asJson(['html' => $html, 'focalPoint' => $focal]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/BaseUpdaterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function actionIndex(): Response
$stateJs = Json::encode($state);
$this->getView()->registerJs("Craft.updater = (new Craft.Updater($idJs)).setState($stateJs);");

return $this->renderTemplate('_special/updater', [
return $this->renderTemplate('_special/updater.twig', [
'title' => $this->pageTitle(),
]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function actionGroupIndex(): Response

$groups = Craft::$app->getCategories()->getAllGroups();

return $this->renderTemplate('settings/categories/index', [
return $this->renderTemplate('settings/categories/index.twig', [
'categoryGroups' => $groups,
]);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public function actionEditCategoryGroup(?int $groupId = null, ?CategoryGroup $ca
$variables['groupId'] = $groupId;
$variables['categoryGroup'] = $categoryGroup;

return $this->renderTemplate('settings/categories/_edit', $variables);
return $this->renderTemplate('settings/categories/_edit.twig', $variables);
}

/**
Expand Down Expand Up @@ -225,7 +225,7 @@ public function actionCategoryIndex(?string $groupHandle = null): Response
'New category',
]);

return $this->renderTemplate('categories/_index', [
return $this->renderTemplate('categories/_index.twig', [
'groupHandle' => $groupHandle,
'groups' => $groups,
]);
Expand Down Expand Up @@ -549,7 +549,7 @@ public function actionInputHtml(): Response
}
}

$html = $this->getView()->renderTemplate('_components/fieldtypes/Categories/input',
$html = $this->getView()->renderTemplate('_components/fieldtypes/Categories/input.twig',
[
'elements' => $categories,
'id' => $this->request->getParam('id'),
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function actionIndex(): Response

$variables['widgetTypes'] = $widgetTypeInfo;

return $this->renderTemplate('dashboard/_index', $variables);
return $this->renderTemplate('dashboard/_index.twig', $variables);
}

/**
Expand Down Expand Up @@ -301,7 +301,7 @@ public function actionSendSupportRequest(): Response
$getHelpModel->attachment = UploadedFile::getInstanceByName($namespace . 'attachAdditionalFile');

if (!$getHelpModel->validate()) {
return $this->renderTemplate('_components/widgets/CraftSupport/response', [
return $this->renderTemplate('_components/widgets/CraftSupport/response.twig', [
'widgetId' => $widgetId,
'success' => false,
'errors' => $getHelpModel->getErrors(),
Expand Down Expand Up @@ -434,7 +434,7 @@ public function actionSendSupportRequest(): Response
}

if (isset($requestException)) {
return $this->renderTemplate('_components/widgets/CraftSupport/response', [
return $this->renderTemplate('_components/widgets/CraftSupport/response.twig', [
'widgetId' => $widgetId,
'success' => false,
'errors' => [
Expand All @@ -445,7 +445,7 @@ public function actionSendSupportRequest(): Response
]);
}

return $this->renderTemplate('_components/widgets/CraftSupport/response', [
return $this->renderTemplate('_components/widgets/CraftSupport/response.twig', [
'widgetId' => $widgetId,
'success' => true,
'errors' => [],
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ElementIndexesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function actionGetSourceTreeHtml(): Response
$sources = Craft::$app->getElementSources()->getSources($this->elementType, $this->context);

return $this->asJson([
'html' => $this->getView()->renderTemplate('_elements/sources', [
'html' => $this->getView()->renderTemplate('_elements/sources.twig', [
'elementType' => $this->elementType,
'sources' => $sources,
]),
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ElementSelectorModalsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function actionBody(): Response
})();

return $this->asJson([
'html' => $this->getView()->renderTemplate('_elements/modalbody', [
'html' => $this->getView()->renderTemplate('_elements/modalbody.twig', [
'context' => $context,
'elementType' => $elementType,
'sources' => $sources,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ private function _contextMenu(
$showDrafts ||
($element->hasRevisions() && $element::find()->revisionOf($element)->status(null)->exists())
) {
return Craft::$app->getView()->renderTemplate('_includes/revisionmenu', [
return Craft::$app->getView()->renderTemplate('_includes/revisionmenu.twig', [
'element' => $element,
'showDrafts' => $showDrafts,
'supportedSiteIds' => $propSiteIds,
Expand Down Expand Up @@ -1187,7 +1187,7 @@ public function actionSaveDraft(): ?Response
$tabs = $form->getTabMenu();
if (count($tabs) > 1) {
$selectedTab = isset($tabs[$this->_selectedTab]) ? $this->_selectedTab : null;
$tabHtml = $view->namespaceInputs(fn() => $view->renderTemplate('_includes/tabs', [
$tabHtml = $view->namespaceInputs(fn() => $view->renderTemplate('_includes/tabs.twig', [
'tabs' => $tabs,
'selectedTab' => $selectedTab,
], View::TEMPLATE_MODE_CP), $namespace);
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function actionCreate(?string $section = null): ?Response
if (!in_array($site->id, $editableSiteIds)) {
// If there’s more than one possibility and entries doesn’t propagate to all sites, let the user choose
if (count($editableSiteIds) > 1 && $section->propagationMethod !== Section::PROPAGATION_METHOD_ALL) {
return $this->renderTemplate('_special/sitepicker', [
return $this->renderTemplate('_special/sitepicker.twig', [
'siteIds' => $editableSiteIds,
'baseUrl' => "entries/$section->handle/new",
]);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/FieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function actionEditField(?int $fieldId = null, ?FieldInterface $field = n
$view->registerAssetBundle(FieldSettingsAsset::class);
$view->registerJs($js);

return $this->renderTemplate('settings/fields/_edit', compact(
return $this->renderTemplate('settings/fields/_edit.twig', compact(
'fieldId',
'field',
'allFieldTypes',
Expand Down Expand Up @@ -287,7 +287,7 @@ public function actionRenderSettings(): Response
$field = Craft::$app->getFields()->createField($type);

$view = Craft::$app->getView();
$html = $view->renderTemplate('settings/fields/_type-settings', [
$html = $view->renderTemplate('settings/fields/_type-settings.twig', [
'field' => $field,
'namespace' => $this->request->getBodyParam('namespace'),
]);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/FsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function actionIndex(): Response
$variables = [];
$variables['filesystems'] = Craft::$app->getFs()->getAllFilesystems();

return $this->renderTemplate('settings/filesystems/_index', $variables);
return $this->renderTemplate('settings/filesystems/_index.twig', $variables);
}

/**
Expand Down Expand Up @@ -112,7 +112,7 @@ public function actionEdit(?string $handle = null, ?Fs $filesystem = null): Resp
->addCrumb(Craft::t('app', 'Filesystems'), 'settings/filesystems')
->action('fs/save')
->redirectUrl('settings/filesystems')
->contentTemplate('settings/filesystems/_edit', [
->contentTemplate('settings/filesystems/_edit.twig', [
'oldHandle' => $handle,
'filesystem' => $filesystem,
'fsOptions' => $fsOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/GlobalsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function actionEditContent(string $globalSetHandle, ?GlobalSet $globalSet
]);

// Render the template!
return $this->renderTemplate('globals/_edit', [
return $this->renderTemplate('globals/_edit.twig', [
'bodyClass' => 'edit-global-set',
'editableGlobalSets' => $editableGlobalSets,
'globalSet' => $globalSet,
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/GraphqlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function actionGraphiql(): Response
$schemas[$name] = $schema->uid;
}

return $this->renderTemplate('graphql/graphiql', [
return $this->renderTemplate('graphql/graphiql.twig', [
'url' => UrlHelper::actionUrl('graphql/api'),
'schemas' => $schemas,
'selectedSchema' => $selectedSchema,
Expand Down Expand Up @@ -362,7 +362,7 @@ public function actionViewSchemas(): Response
// Ensure the public schema is created.
Craft::$app->getGql()->getPublicSchema();

return $this->renderTemplate('graphql/schemas/_index');
return $this->renderTemplate('graphql/schemas/_index.twig');
}

/**
Expand Down Expand Up @@ -419,7 +419,7 @@ public function actionEditToken(?int $tokenId = null, ?GqlToken $token = null):
]);
}

return $this->renderTemplate('graphql/tokens/_edit', compact(
return $this->renderTemplate('graphql/tokens/_edit.twig', compact(
'token',
'title',
'accessToken',
Expand Down Expand Up @@ -503,7 +503,7 @@ public function actionDeleteToken(): Response
public function actionViewTokens(): Response
{
$this->requireAdmin(false);
return $this->renderTemplate('graphql/tokens/_index');
return $this->renderTemplate('graphql/tokens/_index.twig');
}

/**
Expand Down Expand Up @@ -536,7 +536,7 @@ public function actionEditSchema(?int $schemaId = null, ?GqlSchema $schema = nul
}


return $this->renderTemplate('graphql/schemas/_edit', compact(
return $this->renderTemplate('graphql/schemas/_edit.twig', compact(
'schema',
'title'
));
Expand All @@ -562,7 +562,7 @@ public function actionEditPublicSchema(?GqlSchema $schema = null): Response
$token = $gqlService->getPublicToken();
$title = Craft::t('app', 'Edit the public GraphQL schema');

return $this->renderTemplate('graphql/schemas/_edit', compact(
return $this->renderTemplate('graphql/schemas/_edit.twig', compact(
'schema',
'token',
'title'
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/ImageTransformsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function actionIndex(): Response
$variables['transforms'] = Craft::$app->getImageTransforms()->getAllTransforms();
$variables['modes'] = ImageTransform::modes();

return $this->renderTemplate('settings/assets/transforms/_index', $variables);
return $this->renderTemplate('settings/assets/transforms/_index.twig', $variables);
}

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ public function actionEdit(?string $transformHandle = null, ?ImageTransform $tra
$title = Craft::t('app', 'Create a new image transform');
}

return $this->renderTemplate('settings/assets/transforms/_settings', [
return $this->renderTemplate('settings/assets/transforms/_settings.twig', [
'handle' => $transformHandle,
'transform' => $transform,
'title' => $title,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function actionIndex(): Response
$userIcon = file_get_contents($iconsPath . DIRECTORY_SEPARATOR . 'user.svg');
$worldIcon = file_get_contents($iconsPath . DIRECTORY_SEPARATOR . 'world.svg');

return $this->renderTemplate('_special/install', compact(
return $this->renderTemplate('_special/install/index.twig', compact(
'showDbScreen',
'license',
'defaultSystemName',
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/PluginStoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function actionIndex(): Response

$view->registerAssetBundle(PluginStoreAsset::class);

return $this->renderTemplate('plugin-store/_index');
return $this->renderTemplate('plugin-store/_index.twig');
}

/**
Expand Down Expand Up @@ -170,7 +170,7 @@ public function actionCallback(): Response

$this->getView()->registerJs('new Craft.PluginStoreOauthCallback(' . Json::encode($options) . ');');

return $this->renderTemplate('plugin-store/_special/oauth/callback');
return $this->renderTemplate('plugin-store/_special/oauth/callback.twig');
}

/**
Expand All @@ -182,7 +182,7 @@ public function actionModalCallback(): Response
{
$craftIdAccessToken = $this->getCraftIdAccessToken();

return $this->renderTemplate('plugin-store/_special/oauth/modal-callback', [
return $this->renderTemplate('plugin-store/_special/oauth/modal-callback.twig', [
'craftIdAccessToken' => $craftIdAccessToken,
]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/RebrandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function actionUploadSiteImage(): Response
}

$imagesService->loadImage($fileDestination)->scaleToFit(300, 300)->saveAs($fileDestination);
$html = $this->getView()->renderTemplate('settings/general/_images/' . $type);
$html = $this->getView()->renderTemplate("settings/general/_images/$type.twig");

return $this->asJson([
'html' => $html,
Expand All @@ -107,7 +107,7 @@ public function actionDeleteSiteImage(): ?Response

FileHelper::clearDirectory(Craft::$app->getPath()->getRebrandPath() . '/' . $type);

$html = $this->getView()->renderTemplate('settings/general/_images/' . $type);
$html = $this->getView()->renderTemplate("settings/general/_images/$type.twig");

return $this->asJson([
'html' => $html,
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/SectionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function actionIndex(array $variables = []): Response
{
$variables['sections'] = Craft::$app->getSections()->getAllSections();

return $this->renderTemplate('settings/sections/_index', $variables);
return $this->renderTemplate('settings/sections/_index.twig', $variables);
}

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ public function actionEditSection(?int $sectionId = null, ?Section $section = nu

$this->getView()->registerAssetBundle(EditSectionAsset::class);

return $this->renderTemplate('settings/sections/_edit', $variables);
return $this->renderTemplate('settings/sections/_edit.twig', $variables);
}

/**
Expand Down Expand Up @@ -225,7 +225,7 @@ public function actionEntryTypesIndex(int $sectionId): Response
$title = Craft::t('app', '{section} Entry Types',
['section' => Craft::t('site', $section->name)]);

return $this->renderTemplate('settings/sections/_entrytypes/index', [
return $this->renderTemplate('settings/sections/_entrytypes/index.twig', [
'sectionId' => $sectionId,
'section' => $section,
'title' => $title,
Expand Down Expand Up @@ -293,7 +293,7 @@ public function actionEditEntryType(int $sectionId, ?int $entryTypeId = null, ?E
],
];

return $this->renderTemplate('settings/sections/_entrytypes/edit', [
return $this->renderTemplate('settings/sections/_entrytypes/edit.twig', [
'sectionId' => $sectionId,
'section' => $section,
'entryTypeId' => $entryTypeId,
Expand Down
Loading

0 comments on commit 1e5d53d

Please sign in to comment.