Jump to content

Field-Template Context


ryan
 Share

Recommended Posts

Continuing from the Repeaters thread about the field-template context… This video demonstrates how you can adjust the admin context of individual fields according to the template they are placed in. When you adjust the context in this manner, it only changes the settings for when a field appears in that template. This expands the reusability potential of fields across different templates, hopefully preventing the need to create another field if all you really needed was a different title, description or width. You can do this same type of configuration when editing a field in a repeater too.

View this full screen which should put YouTube into HD mode, where it's much easier to see.

  • Like 8
Link to comment
Share on other sites

Continuing from above about the field-template context… This video demonstrates how you can adjust the admin context of individual fields according to the template they are placed in. When you adjust the context in this manner, it only changes the settings for when a field appears in that template. This expands the reusability potential of fields across different templates, hopefully preventing the need to create another field if all you really needed was a different title, description or width. You can do this same type of configuration when editing a field in a repeater too.

View this full screen which should put YouTube into HD mode, where it's much easier to see.

Um... wow!!! This just made my day!

Thanks for the video Ryan. I'm so impressed with the speed of development on ProcessWire. Field contexts should be a UX designers dream. Of all the features lately this is definitely my favourite - so powerful when combined with repeating fields. I have struggled for so long with other CMS's to get the admin interface to become usable and friendly for clients - this is a massive step forward for me - as constantly creating new fields for various templates just to change a field title was a tad cumbersome.

I really like the modal windows to set the new field contexts along with the width settings - so useful.

  • Like 1
Link to comment
Share on other sites

:o

My jaw is somewhere near the floor after that video ryan - that's amazing!

Not only due to the fact that you can give names and descriptions (amongst other things) for fields on a per-template basis, but also seeing a very good usage scenario for the resized field widths! I hadn't thought of anything as useful as that yet but can definitely see quite a few templates where that sort of layout is going to work so I'm going to start playing with them right now to vastly improve my templates ^_^

  • Like 1
Link to comment
Share on other sites

The field-template context is now committed to the source, so it is ready to use. Please let me know how it works for you guys. You can access it from any template or repeater field by clicking on a field name in the asmSelect list. When you first add a new field to an existing asmSelect, the context option isn't yet available. You have to save the template before you'll see the option to alter its context.

When editing a field (from Setup > Fields), you will also see a context pulldown in the upper right corner. This is just a shortcut when/if you want it.

--

Edit: you may need to hit 'reload' in your browser once or twice if you aren't seeing the field context option at first (old files may be stuck in cache).

  • Like 3
Link to comment
Share on other sites

It works great Ryan! I'm in love with this new feature!

Repeated fields and field-template context, used in the right amount, are extremely powerful for creating a friendly edit environment. I really think this brings PW to a new dimension :)

  • Like 2
Link to comment
Share on other sites

I am really loving this feature, great stuff Ryan!

One very minor thing I noticed: if you have added template context settings for title field, it doesn't use those on /page/add/?parent_id=12008 page (first view when adding new pages).

Link to comment
Share on other sites

Thanks Antti, just fixed in latest commit. This applies to situations where you are adding a page somewhere and only 1 template is allowed (per the parent page's template family settings).

Link to comment
Share on other sites

This is really useful.

I have some suggestion:

to add a button to a modal dialog: "Restore Defaults".

Are you planning to add the ability to create context aware field.

$inputfields = parent::___getConfigInputfields();
$field = $this->modules->get("InputfieldTextarea");
$field->attr ('name', 'name');
$field->useInContext = true; //something like that
$field->label = $this->_ ("Label");
Link to comment
Share on other sites

to add a button to a modal dialog: "Restore Defaults".

We may have to add a button like that soon. Currently it restores defaults when you set it to the blank/original unset value. But of course that prevents you from overriding a default populated value with an unpopulated one. So currently it's best to leave the default (no context) value blank if you want it to be blank/unset in any alternate template contexts. Luckily, I don't think that's a common situation (at least not here).

Are you planning to add the ability to create context aware field.

I'm not sure that I understand? There isn't a foundation for context outside of multiple template/fieldgroups, but maybe I'm not reading this right. Can you give me a more specific example or what you mean?

Link to comment
Share on other sites

I asked exactly what is mentioned here;)

Being able to change the other field settings (beyond label, description, columnWidth, visibility) is actually supported in the core, but I've got the system blocking it right now because I'm worried about side effects here.

For example:

If I wanted to create AnotherImageInputField, which would allow me to set a"Minimum files allowed" in the options.

Then in the settings of each template, I could override this setting if it was needed.

But really, I can always create a new field for each template.

So I actually think it is better not to complicate simple things. I use the PW too short to know whether such a possibility would be useful ;)

small-logo.png

Link to comment
Share on other sites

If I wanted to create AnotherImageInputField, which would allow me to set a"Minimum files allowed" in the options.

Then in the settings of each template, I could override this setting if it was needed.

I think this is a good example of why I'm a little scared of supporting context for any factor. If you set "max files" to "1" in one context, and "0" in another, then those fields are going to behave differently from the API (Pagefile vs array of Pagefiles). Same thing with a Page reference field, where you can define its type with the field (Page, PageArray, NullPage, false). I think it could cause a confusion and bugs in people's code.

Another example is just a plain text field. It might have an entities encoder added to it in one context, and not in another. That could be not just confusing, but an output and potential security issue (depending on the source of the text). Uncontrolled field contexts are a bit of a can of worms. :) So before we open up context beyond the existing built-in factors, I want to come up with a way for fieldtype authors to identify a factor as being safe (or not safe) for multi-context.

Link to comment
Share on other sites

I just installed the latest updates :)

Awesome stuff Ryan! I can now spend more time thinking about what I want out of my site and less about the admin UX hurdles I was anticipating.

@Soma I had the same problem with settings not saving and then I remembered your post about clearing the cache. Problem solved!

Link to comment
Share on other sites

It was not working with Safari, only with Chrome, but the latest version, fixed this, I've tested myself and it is working.

What browser are you using, marcin? is ProcessWire the latest version?

Best

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...