Jump to content

Search the Community

Showing results for tags 'contexts'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 2 results

  1. This module corrects a few things that I find awkward about the "Add New Template" workflow in the PW admin. I opened a wishlist topic a while back because it would good to resolve some of these things in the core, but this module is a stopgap for now. Originally I was going to share these as a few standalone hooks, but decided to bundle them together in a configurable module instead. Add Template Enhancements A module for ProcessWire CMS/CMF. Adds some efficiency enhancements when adding or cloning templates via admin. Features Derive label from name when new template added: if you like to give each of your templates a label then this feature can save some time. The label can be added automatically when templates are added in admin, in admin/API, or not at all. There are options for underscore/hyphen replacement and capitalisation of the label. Edit template after add: when adding only a single template, the template is automatically opened for editing after it is added. Copy field contexts when cloning: this copies the field contexts (a.k.a. overrides such as column width, label and description) from the source template to the new template when using the "Duplicate/clone this template?" feature on the Advanced tab. Copy field contexts when duplicating fields: this copies the field contexts if you select the "Duplicate fields used by another template" option when adding a new template. Usage Install the Add Template Enhancements module. Configure the module settings according to what suits you. https://github.com/Toutouwai/AddTemplateEnhancements https://modules.processwire.com/modules/add-template-enhancements/
  2. Micro Contexts (aka field value contexts) Change any context-enabled setting in your page editor/template based on the value of a page reference field. Why use this? Say you have a template that is controlling some generic part of your website, like a section on the homepage, a widget, or an item in a media library. If you are using the various fields on this template in different ways depending on an option (page select) such as 'widget_type', 'media_type', etc, you can hot-switch the template context based on the field's value. Why not use template, like just change the template? Unfortunately, most of my clients would probably break down in tears if i tried to explain what a template is, or how to change it. This also allows you to have better more relevant labels, descriptions and notes based on any page ref field value on your template, as well as be able to show/hide fields based on that value, or even move fields around to make some more prominent or visible. How to use this 1.) Create a new template: 1a) Use the following name structure: mc-[field_name]-[field_value]-[any_memo_here] where [field_name] is the field that will control the micro context, and the [field_value] is the required value (page id) that the controller field must equal/have in order to trigger the virtual template context. The last part of the template name should be used for the page name, or some memo to make it easier to know from the templates list what field value will trigger the micro context, since the template name does require the ID value of the field, not the name. 1b) Make sure to specify the template you are contextualizing under "Duplicate fields used by another template" before clicking save! 1c) Edit your field settings for this template, for when your fieldname=value as specified in the template name (labels, descriptions, notes, visibility, field order etc.) 2.) Place this code in your ready.php file: wire()->addHookAfter('ProcessPageEdit::loadPage', null, function (HookEvent $e) { $page = $e->return; $mcPlates = $this->wire('templates')->find("name^=mc-"); if(!count($mcPlates)) return; foreach($mcPlates as $mcPlate) { $nameParts = explode('-', $mcPlate->name); // expected format: mc-[field_name]-[page-id]-[anything-you-want-here] $mc_field = $nameParts[1]; // the field controlling the micro context $mc_value = $nameParts[2]; // page id has to be the 3rd part of the template name $controllerField = $page->fields->get($mc_field); //if we find a matching controller field from the template name... if($controllerField) { $f_value = $page->get($controllerField->name); $proceed = false; if( ($f_value instanceof PageArray) || ($f_value instanceof Page) ) $proceed = true; // this only works with page reference fields. if(!$proceed) continue; // the page corresponding to the required value (page id) specified in the mc template name, to change micro context $mc_page = wire('pages')->get((int) $mc_value); // if the value specified in the mc template name matches the current value of the page reference field, change the // fieldgroup context $proceed = false; if( $f_value instanceof PageArray && $f_value->has($mc_page) ) $proceed = true; if( $f_value instanceof Page && $f_value == $mc_page ) $proceed = true; if($proceed) { $tName = $mcPlate->name; $mc_template = wire('templates')->find("name=$tName")->first(); if($mc_template) { $mc_fieldgroup = $mc_template->fieldgroup; $page->template->fieldgroup = $mc_fieldgroup; } } } } }); Caveats This probably needs more work to be fully usable, and may need more bullet proofing in terms of checking for valid template name, etc. You can only have this work with 1 page reference field per template. This has been tested and is being used on at least 2 live sites, but caution should be used, and the functionality should be tested before using on a live site. Screenshots: 1) a default widget with no field value context enabled fields 2.) A field value context enabled edit page for the 'Widget Type', the template controlling this is now 'mc-widget_type-1054-text', but the template of the page stays as 'widget'; only the fieldgroup context is changed when the page is loaded to get the contextual settings: 3.) the context for when the page reference field called 'widget_type' has the value of 1150, which is a video widget type (template name is 'mc-widget_type-1150-video'). Convenient Module edition coming soon!
×
×
  • Create New...