About Field Name Unprefixer

Makes it possible to access prefixed field names without the prefix.

Category 1Development Tools
Modules that have more to do with assisting development of a site rather than managing its content.
Category 2Proof of Concept
Proof of concept modules are designed as examples or starting points for others to build from. May not be ideal for users wanting to plug-n-play.
Release StateDelete
State reserved for modules pending deletion at author's request.*
Authorowzim
Module Version0.1.1
Class NameFieldnameUnprefixer
Compatibility2.5, 2.6, 2.7
Date AddedOctober 25, 2014
Last UpdatedDecember 11, 2016
Recommended ByNew recommendations may take up to 1 day to appear.

Instructions

This module's files should be placed in /site/modules/FieldnameUnprefixer/
How to install or uninstall modules

README

Field Name Unprefixer

for ProcessWire 2.5

Makes it possible to access prefixed field names without the prefix.

Usage

Create some prefixed fields and add it to you desired template, for example prefix_myField and otherPrefix_myOtherField.

Configure the prefixes, that should be removed in your /site/config.php, like so:

$config->FieldnameUnprefixer = array(
	'basic-page' => array('prefix_', 'otherPrefix_'),
	'home' => array('prefix_', 'otherPrefix_')
);

The first array keys are the template names.

The Prefixes also can be assigned as a string if it's just a single one:

$config->FieldnameUnprefixer = array(
	'basic-page' => 'prefix_',
	'home' => 'otherPrefix_'
);

Now you can access the fields without the prefix, like so:

echo $page->myField;
echo $page->myOtherField;

The unprefixed field names are now also accessible via selectors, but only for already fetched data, since the field is not really in the database:

// not
$pages->find('myField=something');
// but
$pages->find('template.name=basic-page')->filter('myField=something');

Use case

Prefixes are sometimes necessary to have fields that behave specific to the template, so you need to create a specific field and namespace it with a prefix, but don't want to access the fields differently on each template.

// eeew!
$client->client_address;
$something->something_address;

// yay!
$client->address;
$something->address;

TODO ...

Change Log

0.1.0

  • initial version