Field - Using a *- or **-mapping (also called wild card-mappings)
From Perfion 4.5 2019 R1 a * (star) can be used instead of a features name in a Field-Mapping (and only in a Field-Mapping). Doing that will automatically map all features in the View specified in the Context-node not already mapped explicitly (i.e. by another mapping).
Table 1 provides an example having a *-mapping:
Field – *-mapping | ||
What can be output | Supports | Supported Entities |
a Features r Attributes r Literals | a Multi value features a Localizable features r Output Kind Parameters | a Site a Category a Product a Variant |
Sample Mappings | ||
| ||
Sample Configuration | ||
| ||
Sample output | ||
<Product id="636" ecommerceproduct="983ST">
<Fields>
<Field name="Item No">983ST</Field>
<Field name="EANCode">5709846014466</Field>
<Field name="Image">a10a14e0-7f66-4d87-8adc-a4b0e10ecf11</Field>
<Field name="ItemName" culture="en-US">Vacuum Jug EM77 Yellow</Field>
<Field name="ItemName" culture="de-DE">Vacuum Jug EM77 Yellow</Field>
<Field name="ItemName" culture="da-DK">Vacuum Jug EM77 Yellow</Field>
<Field name="RetailPrice">49.95</Field>
</Fields>
…
</Product>
|
Table 1: Summary of output kind Field using a Wild Card-mapping.
In Table 1 we have 4 mappings:
A Context-node telling that products can be found in feature “Product” and that we use the WebDetail Standard View (see more on the Context-mapping).
A Key-Field mapping the base value to “Item No” (Described in Section KeyField).
A *-mapping (also called a wild card-mapping) which will be described below.
A mapping of the Feature RRP to the Field Retail Price. Such a mapping is called an explicit mapping (as opposed to a wild card-mapping).
As can be seen from Table 1 the single *-mapping results in 3 Fields being added to the output: EANCode, ItemName and Image. Why it is exactly these 3 features is described here:
The *-mapping considers the Standard View for the applicable Context-node. In the example above, WebDetail is specified, but it can be any of the standard views in the Perfion API (see which views that are available in the Perfion API-documentation). If no view is specified in the Context-node (as it is done in Table 2 where it only maps from “Product”) WebDetail is picked by default. You can specify “no view” using a “-“ (dash) instead of a view name, and that will effectively disable wild card mappings.
As can be seen in the table the Configuration indeed has these 3 features checked as being in “WebDetail” (and a 4th feature named RRP that is not output as a result of the *-mapping due to the next bullet).
The *-mapping only outputs Features that does not already have an explicit mapping. This is the reason why the RRP-feature is not output by the *-mapping. It simply has an Explicit Mapping, mapping it to a Field named “Retail Price” so it will not be output again as a result of the *-mapping.
The *-mapping names the output fields precisely as their corresponding features. If you need to name an output field different from its feature, you need to create an explicit mapping for it. To put it differently the “To”-value for the *-mapping is ignored in these versions.
This changed in from versions 4.7.9 and 4.8.2. From these you can now specify a “To”-value for the *-mapping. This allow you to add a fixed prefix, postfix or both to the Fields output by the *-mapping.
The *-mapping only outputs Fields, meaning that an image is usually not appropriate to output using a *-mapping as done in the example.
The *-mapping does never output a base value. If a mapping of a base value is needed, you would need an explicit mapping from “Value”-feature.
The *-mapping only output non-remote features. From version 4.10.0, however, it is possible to use a **-mapping, which will output both non-remote and remote features.
In previous versions of Perfion (before 4.5 2019 R1) all features you wanted to output needed an explicit mapping. Now you only need an explicit mapping if you need another Output Kind than Field or you need to rename it.
NOTE: For a *-mapping to work the Output Kind must be set to Field. Otherwise, it will not output anything. In addition, the view may not be set to – (meaning no view. See more in Section Context-mapping).
NOTE: It does not make sense to have more than one Wild Card-mapping (per channel/entity combination).
Adding prefix or postfix the Field-names generated
Up to versions 4.7.8 and 4.8.1 the output fields from the *-mapping names are named precisely as their corresponding features. If you needed to name an output field different from its feature, you needed to create an explicit mapping for it. To put it differently the “To”-value for the *-mapping is ignored in these versions.
Beginning from version 4.7.9 and 4.8.2 you can now specify a “To”-value for the *-mapping. This allow you to add a fixed prefix, postfix or both to the Fields output by the *-mapping.
Example: Consider the example in Table 5 but assume that instead of having a blank To-Value, as shown in the table, you had instead entered “AA_*_BB”. In this case the field created by the “ItemName”-feature would no longer simply be called “ItemName”, instead it would get prefixed by “AA_” and postfixed by “_BB” and hereby be called “AA_ItemName_BB”.
To use this the “To”-value must contain a “*” denoting the position of the feature-name in the output Field-name. It is allowed to specify, for example “PREFIX_*” as “To”-value. This simply means, that there is no postfix in. Specifying a “*” is the same as having a blank value, i.e. the feature name will be used. Not specifying a “*” in the “To”-value, which is wrong, will simply output the Feature-name.
NOTE: When using the **-mapping introduced in 4.10.0 it is still a single * that specifies the position of the feature name.