owzim Posted October 24, 2014 Share Posted October 24, 2014 GitHub: https://github.com/owzim/FieldnameUnprefixer From the README.md: 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; Might be not the ProcessWire-way because data access is abstracted, but I use it, and perhaps some of you find it useful too. 9 Link to comment Share on other sites More sharing options...
Mike Rockett Posted February 7, 2015 Share Posted February 7, 2015 Thanks for this, Owzim - I do think it's a great module to have. Any way I can apply a prefix-check to all templates? I'm showing data in a footer, gathered from the home page, so I don't want to specify the prefix for every template I create... Link to comment Share on other sites More sharing options...
owzim Posted February 13, 2015 Author Share Posted February 13, 2015 Hi Mike, not possible at the moment, but I just looked into the code, should be easy to implement, with selectors. Instead of $templates->get("name"), I would use $templates->find("selector"), and loop through them. But it needs to be tested as well and unfortunately I haven't got the time at the moment. Feel free to make a PR PS: it's owzim 1 Link to comment Share on other sites More sharing options...
Mike Rockett Posted February 13, 2015 Share Posted February 13, 2015 Hi owzim I see. If I get some time, I'll make a PR. Ah, right - force of habit, I guess. ;-) Link to comment Share on other sites More sharing options...
Nico Knoll Posted February 13, 2015 Share Posted February 13, 2015 I deleted the post you wanted to delete and kongondo's question why you want to delete it. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now