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

  • ProcessWire 3.0.185 (dev) core updates, plus new Session Allow module— More
    17 September 2021
  • Three new ProcessWire Textformatter modules: Find/Replace, Markdown in Markup, and Emoji— More
    3 September 2021
  • This week we have a new master version released after a year in the making. With nearly 40 pull requests, hundreds of new additions and more than 100 issue reports resolved, this new version has a ton of great new stuff— More
    27 August 2021

Latest news

  • ProcessWire Weekly #384
    In the 384th issue of ProcessWire Weekly we'll cover the latest core updates, introduce a new module called Session Allow, and highlight a new site of the week. Read on!
    Weekly.pw / 18 September 2021
  • ProcessWire 3.0.184 new master/main version
    This week we have a new master/main version released after a full year in the making. As you might imagine, this new version has a ton of great new stuff and we’ll try to cover much of it here.
    Blog / 27 August 2021
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer