Can I define page types in my theme (instead of building them out in the backend)?
Created 6 years ago by immersiontravisThe "Creating Your First Page" video explains how backend users can create custom page types.
However, I'd prefer to define page types and templates in my theme, for three reasons:
- I want to source-control my page types.
- It fits more naturally with my development workflow. When building a theme, I typically edit CSS, layout-level HTML, and page-level HTML all at the same time. I'd rather stay in my IDE for this, instead of jumping over to the backend to edit page-level HTML.
- I don't want backend users to be able to edit page types. In other words, I want page types and templates to be defined by the developer at development time, not by the backend user after launch. (I'm sure that I could prevent this via user permissions – so consider this a bonus reason, I guess.)
So: is it possible to do this? There seems to be a CMS trend toward giving backend users the ability to create arbitrary layouts – but in my experience, giving clients that freedom is a great way to end up with a trashy site.
Thanks for the info. That's very annoying, though – I still have to use the Pages backend to scaffold the files for each page type, and then I have to fiddle with the environment settings whenever I deploy/update those files on production.
Um, currently you can.
- a) You can use Theme Layout instead of Types.
By default the normal Theme Layout are using:
{% block content %}{% endblock %}
And page use it like that:
{% block content %}
{% block page %}
{{ content|raw }}
{% endblock %}
{% endblock %}
{{ content|raw }}
is the full HTML (Types included), but you can use {{ page.title }} for example, or anything else.
- b) You can also just use Seeder in your theme or module that will seed the good Types.
- Same as 1.
- Just remove the user access to Types.
Something that will be making it to the roadmap but that is not yet a fully developed idea is generating migrations from existing data. Which would let us generate page types once and then automate migrations for them.
If yo use blocks though, this is less of an issue as your blocks can be distributed across projects. In this way we've all but eliminated the need for page types other than the home page in 90% of our use cases. Comes in handy though for design
Nope, those also only sync up to the DB during development (once set as production it will no longer sync from file to db).
Permissions is the right way to remove the ability for clients to modify, as for the source control issue, add the storage path to your repo and you should be good to go.