1

One of my biggest issues with craft so far is having to type out which template file a section is using, I don't understand why we don't have a location to enter all our possible templates, which could then be chosen when creating sections "new pages" etc. Or having craft know which template files exist.

Could this be possible via a plugin, or would the core need to be modified. Having to explain to a client they need to know the name and location of a template file when creating new pages isn't great.

Updated Scenario:

Simple example, say I have news post, and events, and I want an index of both as well as single news post and single events both using different templates. When a client wants to create a new event, they would need to know the name of the template that is used for single events otherwise it would default to index.html if the auto generated entry-template name doesn't exist.

When creating a new entry craft defaults to a news item or I call it a news "post". So to create a new event, I need to create a new section, and then specify the entry-template otherwise it defaults to the name of the section, and if no template exists for that entry template "which ends up being the name of the section" it defaults to the index.html template. Then they still need to assign fields to each section that is created. The assigning fields can be simplified by creating a group say called Single Events, with all the possible fields allowed for that type of section "page" this case being single events...

The only easy solution I can think of is to not use groups at all for fields, and just throw every field into each section, then in the index.html template check for each field and if it exists before displaying it. But what about not wanting to display it or displaying dynamic content based on the entry type news post vs single event vs team members vs resources vs contact forms. A solution to that is creating another field called content type with a drop down for single event, team member, resources, contact form... then in the index.html template check the value of the drop down before determining what is going to be displayed and what isn't.

My whole point is it seems like this could all be simplified by having a drop down to choose a template when creating a section since a section needs to be created so that you can create a new entry that is not a news post, and I also think once you create a new section it should allow you to either start editing that section, or take you to the field selection to add fields to that section, after you save a section it just takes you back to the sections which you then have to click edit entry types to choose which fields are used for that section.

To me it would make more sense to have fields assigned to templates, and sections are just holders for "entries" or what I call pages. Example basic-page.template has a bunch of fields assigned to it. I create a section called about us, and choose basic-page.template after saving the section allow me to start editing the entry for that "section".

Sorry for the wall of text just trying to give some examples and I hope they make sense. Just trying to understand the concept of some of this, I'm getting by but it seems odd not to allow to choose a template that is used unless you are a dev on the project and know exactly the name of the template.

  • 4
    If you let the clients create sections, I'd say that you're using craft wrong. If you provide more information about your setup maybe it'd be possible to provide a solution that solves this without having to fundamentally change how Craft work. – André Elvan May 6 '15 at 18:07
  • So what you are saying is if you want your clients to be able to create pages then don't use craft? I don't see the logic in that. I can easily create great page builders using matrix fields and check for blocks in a page template. Maybe some templates I will check for specific blocks/fields etc. Say basic page template, form template, rss feed template. Different news types or styles... Either way doesn't make sense to not have it, if anything make it a global option... – Bowenac May 7 '15 at 1:44
  • "Pages" isn't a term used in Craft, and Sections are just containers for your content (entries). Could you elaborate on what you mean by "new page", and/or add a brief description of what you're trying to build? – Mats Mikkel Rummelhoff May 7 '15 at 9:21
  • Bowenac, cheers for the extended info. Is this a Craft Personal edition install? – Mats Mikkel Rummelhoff May 7 '15 at 15:15
  • Yes personal edition. – Bowenac May 7 '15 at 15:58
5

Short answer – no, there isn't any way to add a dropdown for template selection to Sections without modifying the core (which is never a good idea).

Beyond that, its difficult to advice without a brief description on what you're attempting to build. Craft is generally perfect for flexible, modular content and layouts, and what you want to achieve is most likely very doable – but I suspect your approach may be a little misguided.

Sections in Craft are the basic containers for your content, and creating a whole new Section should never be part of the basic editorial workflow.

If the OP provides a little bit more context, I'll try update this answer with a suggested approach.

EDIT:

Your problem is that you're using Singles – one of three possible Section types – as entries in a stream of content (events). This is not a feasible workflow. Singles are meant as one-offs; completely unique bits of content that doesn't fit anywhere else and needs its own, unique field layout and/or template.

Any content that is part of a stream, such as a blog post, news item or event listing should be published as actual entries to either a Channel or a Structure Section (in your case I'd use Channels for both news and events; the latter is only appropriate if you need to nest entries or put them in a specific order).

Using a Channel or Structure means that whatever template you specified when you created the Section will be automatically loaded for all its individual entries, and your client will also not need to re-create the field layout every time they want to publish something.

Obviously, with Craft Personal edition, you're limited to only one Channel – and you specifically need two. You have two options:

  1. Upgrade to Craft Client/Pro. If you want to test it out before purchasing, see this page for info.
  2. Delete the News channel and create a new, generic channel called "Content" or the like. Create two different Entry Types for the channel, called "News" and "Events". This would enable you to create different field layouts for news and event entries. In your channel's entry template, you could then do something like this:

    {% if entry.type == 'event' %} {% include 'event.html' %} {% else %} {% include 'news.html' %} {% endif %}

Note that this solution will not really scale well at all, and the editorial workflow would also be subpar compared to having separate channels. I'd strongly recommend the first approach :)

Finally, I'm not familiar with ProcessWire and couldn't advice which is better for your specific project, although your site would be a doozy to set up in Craft – as long as you apply its concepts and tools the way they're meant to be used. Obviously, if you're coming from ProcessWire or any other CMS (like Wordpress or ExpressionEngine) it can take a little time to adapt to a different terminology, toolset and workflow and to absorb platform best practices. I'd advise you to read through the basic docs (they're quite concise) for a better understanding of how Craft manages content, and to give Craft Client or Pro a test run before deciding.

  • Thanks client is set on using craft so we will purchase pro, IMO this would actually be simpler with ProcessWire but I do like craft as well. It just seems like processwire has a lot more configurable options. Will see how the rest of this project goes, and who knows might strictly start using craft if I end up liking it more. – Bowenac May 7 '15 at 20:57
  • Ran into another issue that is kind of related in a way, I ended up setting up a dev.craft for dev using pro so now I have access to channels BTW thanks. If you would like to look over my other question that would be awesome craftcms.stackexchange.com/questions/9659/… – Bowenac May 8 '15 at 15:34
1

There is a template select plugin, I've used it before and it worked.

http://straightupcraft.com/craft-plugins/template-select

  • 1
    Template Select adds a custom FieldType to Craft. While a great way to add template selection to entries, categories, assets and users, it's not possible to add custom fields to Sections. – Mats Mikkel Rummelhoff May 6 '15 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.