About Concatenate Fieldtype

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.

Category Field Types
Fieldtype modules that represent a data type used by fields.
Release StateStable
Should be safe for use in production environments. *
Authorryan
Module Version1.0.6
Class NameFieldtypeConcat
Compatibility2.2, 2.3, 2.4, 2.5, 2.6, 2.7
Date AddedDecember 31, 2012
Last UpdatedOctober 14, 2014
Recommended ByNew recommendations may take up to 1 day to appear.

Details

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.

Instructions

  • 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:

Code:
echo $page->full_name;

README

FieldtypeConcat

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 ofseparately 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 inthe 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 haveto update the name in your Concat field settings as well.
  • By design, Concat fields do not inherit the text formatters of the fields theyconcatenate. 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

  1. Install the module by placing FieldtypeConcat.module in /site/modules/.
  2. Check for new modules on the Modules screen in the ProcessWire admin.
  3. Click Install for the Concat Fieldtype.

How to Create a Concat Field

  1. Under Setup and Fields create a new field using type Concat.
  2. After entering the new field name and label, click Save.
  3. Click the Details tab and enter one or more field names. Separate them with whateverspacing and punctuation is appropriate.
  4. Optionally choose one or more Text Formatters. If you are not sure which, “HTML Entity Encoder”is a good default to use.
  5. Save.
  6. 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;

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

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.