FieldtypeConcat by Ryan Cramer

Fieldtype that concatenates the values from one or more other fields at runtime. The resulting value can also contain additional formatting and/or words as needed.

h1. FieldtypeConcat

h2. 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.


h3. 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.


h3. 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.


h3. 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.


h3. 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.


h3. 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.


h3. 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:

bc. echo $page->full_name;

h3. Using subfields

In addition to regular field names, you can also reference properties of object-based fields like
Page references and parents. For example @parent.title@, @parent.parent.path@, @categories.name@,
and so on.

-----------------------
Copyright 2015 by Ryan Cramer

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Twitter updates

  • New post: Multi-language field translation export/import — In this post we cover the details of a new module that enables export and import capabilities for multi-language fields in ProcessWire… More
    5 August 2022
  • Weekly update, July 29: Continuing upgrades to ProcessWire’s comments system and FormBuilder, along with a working example—More
    29 July 2022
  • Weekly update for July 22– Looking back at what web development was like in the year 2000. Plus some more discussion on the path from CKEditor 4 to CkEditor 5 in ProcessWire: More
    22 July 2022

Latest news

  • ProcessWire Weekly #430
    In the 430th issue of ProcessWire Weekly we're going to check out some brand new third party modules, a new site of the week, and more. Read on!
    Weekly.pw / 7 August 2022
  • Multi-language field translation export/import
    In this post we cover the details of a new module that enables export and import capabilities for multi-language fields in ProcessWire.
    Blog / 5 August 2022
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani