ryan Posted December 31, 2012 Posted December 31, 2012 ProcessWire Concatenate Fieldtype Fieldtype that concatenates the values from one or more other fields at runtime. The value can contain additional formatting and/or words as needed, which you define in your Concat field settings. Example Problem: Your system has a first_name and last_name field, and you want to have a separate full_name field composed of first_name and last_name, without redundancy. Solution: You would create a new Concat field, click the details tab, and enter "first_name last_name" (the fields you want to concatenate) in the settings. Other Potential Uses Having a field that combines the value of two or more others, without the redundancy of separately stored data. Defining a custom “label field” for select boxes, like those used with the Page field. Defining a custom label for your Page List that includes your own formatting. Defining an alternate variation of a text field that uses a different text formatter. Considerations The value for this fieldtype is generated at runtime and thus no data is stored in the database. This is good because there is no duplication. However, it also means that you cannot directly query a Concat field from $pages->find(), for example. If you happen to change the name of a field being used in a Concat field, you will have to update the name in your Concat field settings as well. By design, Concat fields do not inherit the text formatters of the fields they concatenate. You define these separately with the Concat field. Because this is a runtime-generated field, there is no Inputfield associated with it. How to Install Install the module by placing FieldtypeConcat.module in /site/modules/. Check for new modules on the Modules screen in the ProcessWire admin. Click Install for the Concat Fieldtype. How to Create a Concat Field Under Setup and Fields create a new field using type Concat. After entering the new field name and label, click Save. Click the Details tab and enter one or more field names. Separate them with whatever spacing and punctuation is appropriate. Optionally choose one or more Text Formatters. If you are not sure which, “HTML Entity Encoder” is a good default to use. Save. Add your new field to one or more Templates. How to access the value of a Concat field This is no different than accessing the value of any other field. If your Concat field has the name “full_name” then you would output its value like this: echo $page->full_name; Download PW Modules Site: http://modules.proce...eldtype-concat/ GitHub: https://github.com/r...FieldtypeConcat 21
ryan Posted January 1, 2013 Author Posted January 1, 2013 Thanks guys. Btw, this module was prompted by the need that Renobird mentioned for multiple field labels with the Page reference input labels. 1
arjen Posted January 1, 2013 Posted January 1, 2013 Thanks, Ryan. This is a very useful addition for admin purposes.
renobird Posted January 2, 2013 Posted January 2, 2013 Hi Ryan, This is great! It seems to be working correctly for me if I use it to create a new field and use it in a template. However, if I use it to set a new "label field" for a select — I'm still getting the default (title). Install is running 2.2.9.
ryan Posted January 4, 2013 Author Posted January 4, 2013 However, if I use it to set a new "label field" for a select — I'm still getting the default (title). Install is running 2.2.9. I can't seem to duplicate here. Can you double check that your new Concat field is attached to the template used by your selectable pages?
renobird Posted January 4, 2013 Posted January 4, 2013 *slaps forehead* Sorry Ryan — works fine. I was testing with user info, and added the field to a custom user template I was testing instead of the system user template. False alarm. Thanks again for this, super useful.
doolak Posted January 31, 2013 Posted January 31, 2013 Would it be somehow possible to display a date field formatted in a concat field? This is displayed as timestamp at the moment. 1
ryan Posted February 2, 2013 Author Posted February 2, 2013 I've updated it so that it can now support using formatted values before concatenation--like you would want with dates. Grab the new version (1.0.1). Then, in your format string, just specify an exclamation point after any field names you want to use the formatted version for. For example, "title, date!" rather than "title, date". 4
doolak Posted February 2, 2013 Posted February 2, 2013 Wow, great! Thanks ryan! (Do you ever sleep?) 2
doolak Posted February 3, 2013 Posted February 3, 2013 Hm, it does not work here. I have updated the module, I have even emptied the assets cache, but the concat field still shows the unformatted date.
Martijn Geerts Posted February 3, 2013 Posted February 3, 2013 Sorry to bug you with this. ( not a real answer to your question ) A new text formatter can be written quickly, so you could attache a custom formatter to it.
ryan Posted February 3, 2013 Author Posted February 3, 2013 @doolak, it's working for me here, but I found it may depend where you are displaying the value. If you are using it for something on the admin side (where output formatting is off by default) it may not have worked. I just updated it to force the output formatting. Try it again with the latest and let me know if it works now? 1
doolak Posted February 3, 2013 Posted February 3, 2013 Yes, i am using it as a label for a Page Field - works fantastico now, thanks again! 1
apeisa Posted March 11, 2013 Posted March 11, 2013 Ryan - when trying to rename concatenate field I get this error: Can't find file: './pw_koulutus_pwire_fi/field_fullname.frm' (errno: 2)
ryan Posted March 12, 2013 Author Posted March 12, 2013 Can't find file: './pw_koulutus_pwire_fi/field_fullname.frm' (errno: 2) I don't think this error is coming from the Concatenate fieldtype, because it does not deal with the file system. I'm also not familiar with what a ".frm" file is? It sounds like there must be some other 3rd party module installed that is triggering this error, but I don't recognize the error or filename format. What modules do you have installed that might be manipulating files?
apeisa Posted March 12, 2013 Posted March 12, 2013 Ryan, it's mysql file: http://dev.mysql.com/doc/internals/en/frm-file-format.html Might have something to do with my environment, will test more soon.
owzim Posted August 6, 2013 Posted August 6, 2013 Hi Ryan, this is a great and useful module. I have some problems with it though: Let's say my concat string looks like this"title - somePagefield.title - someFancyHookedField"the someFancyHookedField is a field on which I manipulate the output with a hook (like described here) Everywhere else in my template files the output of that field works like it should but via the concat fieldtype it stays empty. Maybe the module does not take hooks on fields in consideration? edit: I did not read the description carefully, with an exclamation mark, the formatting of the field takes place and so does then the hook. PS: I get the same error like apeisa when renaming the field, no prio though.
Ryan Pierce Posted March 14, 2014 Posted March 14, 2014 Does / could this work with arrays at all? I've got a template that has a repeater with a page select of the days in a week and sometimes multiple days are selected - can I use this to display just the first title of an array? Right now I'm seeing it return "Array, {other field name}" and ideally it would show "Monday, {other field name}" if all days are checked.
Raymond Geerts Posted August 5, 2014 Posted August 5, 2014 @Ryan in PW 2.4.10 (from 2.4.3 atleast) this module stops working and throws an error "Class 'FieldtypeText' not found" on line 20 class FieldtypeConcat extends FieldtypeText Please see: https://github.com/ryancramerdesign/FieldtypeConcat/issues/3 Changing the line to this, fixed the error, but doesnt seems format the output anymore. class FieldtypeConcat extends Fieldtype
ryan Posted August 5, 2014 Author Posted August 5, 2014 Raymond, Can you try out the update I just pushed to FieldtypeConcat? I couldn't duplicate the issue you are seeing, but I can how why it's feasible to occur. I updated the module to identify it's requirements for ProcessWire 2.5+ dependencies and am wondering if this might resolve the issue. 1
Raymond Geerts Posted September 11, 2014 Posted September 11, 2014 @Ryan running PW 2.5 with FieldtypeConcat without any problems. Thanks for fixing it 1
Lauren Posted November 13, 2014 Posted November 13, 2014 This is exactly what I was looking for! Thank you I'm using it to create a custom "Label Field". However, it shows the ID, versus the title. Is there something I need to do to get it working when concatenating fields of the Page fieldtype? Or does it only support certain fieldtypes, like Text?
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