Skip to content

Commit e7e780b

Browse files
authored
Merge pull request #659 from ExpressionEngine/feature/7.x/template-folder-structure
more info on editing templates and saving as files
2 parents 1137266 + fe09016 commit e7e780b

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

docs/_images/template-edit.png

45.3 KB
Loading

docs/_images/templates-list.png

78.6 KB
Loading

docs/templates/overview.md

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,80 @@ https://example.com/template_group/template
3535

3636
In addition to HTML and other markup, templates usually contain [ExpressionEngine Tags](templates/language.md), which allows information to be served dynamically.
3737

38-
## Creating a Template
38+
## Creating & Editing Templates
3939

4040
Templates can be created and edited in the `Developer -> Templates` area of your Control Panel.
4141

42-
ExpressionEngine, by default, saves Template Groups, Templates, Global Variable, and Template Partials as regular folders and files on your server at `system/user/templates`. This allows you to use your preferred text editor to edit Templates and then FTP the changes to the server.
42+
![Templates List](_images/templates-list.png)
43+
44+
You start off by creating a template group. During creation you will have the option to duplicate an existing group with all of its templates. You can also select the roles that will have editing permissions for templates in this group.
45+
46+
Then, create individual templates. You can duplicate an existing template, or create a blank one. If necessary, change the template type from "Webpage" to the type that you need (RSS Page, CSS, JavaScript, Static, XML)
47+
48+
Existing templates can be edited with the built-in editor, which provides intelligent syntax highlighting.
49+
50+
TIP: **Tip:** The font size in the template editor can be adjusted with a [configuration override](general/system-configuration-overrides.md#codemirror_fontsize).
51+
52+
You can also edit template preferences and set front-end access permissions for the template.
53+
54+
![Template Editor](_images/template-edit.png)
55+
56+
## Saving templates as files
57+
58+
Template Groups, Templates, Global Variables, and Template Partials are always saved into the database and this is their primary source, however by default they are also saved as regular folders and files on your server.
59+
60+
This behavior is controlled by [system configuration overrides](general/system-configuration-overrides.md#save_tmpl_files)in `system/user/config/config.php`:
61+
```php
62+
// Controls whether template and partial files should be saved on filesystem
63+
$config['save_tmpl_files'] = 'y';
64+
// Controls whether Global variables should be saved as files (requires `save_tmpl_files` also being set to `y`)
65+
$config['save_tmpl_globals'] = 'y';
66+
```
67+
68+
The directory structure would be similar to what is shown below:
69+
70+
```
71+
|-- system
72+
| |-- user
73+
| | |-- templates
74+
| | | |-- _global_partials
75+
| | | | |-- _header.html
76+
| | | | |-- _footer.html
77+
| | | |-- _global_variables
78+
| | | | |-- logo.html
79+
| | | |-- default_site
80+
| | | | |-- _partials
81+
| | | | | |-- sidebar.html
82+
| | | | |-- _variables
83+
| | | | | |-- address.html
84+
| | | | |-- blog.group
85+
| | | | | |-- entry.html
86+
| | | | | |-- feed.xml
87+
| | | | | |-- index.html
88+
| | | | |-- home.group
89+
| | | | | |-- contact.html
90+
| | | | | |-- about.html
91+
| | | | | |-- index.html
92+
| | | | |-- styles.group
93+
| | | | | |-- contact.css
94+
| | | | | |-- index.css
95+
| | | |-- second_msm_site
96+
| | | | |-- _partials
97+
| | | | | |-- sidebar.html
98+
| | | | |-- _variables
99+
| | | | | |-- address.html
100+
| | | | |-- home.group
101+
| | | | | |-- about.html
102+
| | | | | |-- index.html
103+
```
104+
105+
This allows you to use your preferred text editor to edit Templates and then transfer the changes to the server.
106+
107+
`default_site` and `second_msm_site` are the site short names if you're running [Multiple Site Manager](msm/overview.md). If you have just one site, `default_site` is going to be the only one you need.
108+
109+
`_partials` folder holds your [template partials](templates/partials.md) for the site, and `_global_partials` holds partials that are shared through all MSM sites.
110+
111+
`_variables` folder holds your [template variables](templates/variable.md) for the site, and `_global_variables` holds variables that are shared through all MSM sites.
43112

44113
These are the naming rules that ExpressionEngine applies to these resources:
45114

@@ -52,7 +121,11 @@ These are the naming rules that ExpressionEngine applies to these resources:
52121
- _.xml_ creates an 'xml' template type
53122
- Template group names (not including the .group) and template names (not including the .extension) are limited to 50 characters. Anything longer than that will be truncated by the database and fail to match the file.
54123

55-
You can also choose to save templates in the database using this [system configuration override](general/system-configuration-overrides.md#save_tmpl_files).
124+
Having several templates with the same name but different extensions is not supported.
125+
126+
The existing templates are synchronized with the files as soon as any site page is accessed. If you created a new template or a new template group on the file system, the pages or edits will be immediately available, though they will not be added to the database until you visit the `Developer -> Templates` section of the Control Panel or the template is visited on the frontend.
127+
128+
NOTE: **Note:** When saving templates as files, `index.html` will be placed automatically into each template group folder when the templates are synchronized.
56129

57130
## Hidden Templates
58131

@@ -85,7 +158,7 @@ Additionally, PHP code in templates will operate slower than same code wrapped i
85158

86159
ExpressionEngine allows you to place [PHP](https://www.php.net/) code within your Templates so that it can be executed, allowing more dynamic capability with your content.
87160

88-
In order for this feature to be available, it needs to be enabled by adding
161+
In order for this feature to be available, it needs to be enabled by adding
89162
```php
90163
$config['allow_php'] = 'y';
91164
```

0 commit comments

Comments
 (0)