Project

General

Profile

Feature proposal #7828

Implement support for nested substitutions

Added by krileon 4 months ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
29 January 2020
Due date:
% Done:

100%

Estimated time:

Description

This should allow for substitutions within substitution attributes. So for example the following could be allowed.

[cb:userfield field="avatar" user="[cb_mentor]" /]

This needs to ensure the resulting value from the nested substitution is substitution safe. Meaning doesn't contain substitutions itself to prevent large substitution loops and to prevent user content being passed through substitutions. So in this case the substitution result must be strict so it should be cast to int unless it's a valid string value for the user attribute (e.g. #me).

History

#1 Updated by krileon 4 months ago

  • Status changed from Assigned to Resolved
  • % Done changed from 0 to 100

Implemented in MR !1528

This is implemented by improving the processing order of substitutions. First raw field substitutions will take place (e.g. [FIELD_NAME]) followed by custom $extraString usages (e.g. [user]). Next userdata, userfield, date, config, etc.. substitutions will take place and last IF substitutions will take place. What this means is since raw substitutions have already parsed BEFORE userdata, userfield, if, etc.. usages you can place the raw substitutions inside of them. Example as follows.

[cb:userfield field="avatar" user="[cb_mentor]" /]
[cb:if user="#me" user_id="[cb_mentor]"]I am this users mentor![/cb:if]

What is not allowed is a userdata inside of a userfield. This is because they are both parsed by the same parsing behavior and logic wise it wouldn't make much since due to being prone to format output errors. So for example the below is not allowed.

[cb:userfield field="avatar" user="[cb:userdata field="cb_mentor" user="#me" /]" /]

The above maybe supported at a later time, but for now it is not and only raw nesting will be supported. In addition to this a below usecase is no longer supported due to the processing order change.

[cb:userfield field="avatar" user="[cb:if user_id="myid"]#displayed[cb:else]#me[/cb:else][/cb:if]" /]

This usecase would just be written as follows instead.

[cb:if user_id="myid"][cb:userfield field="avatar" user="#displayed" /][cb:else][cb:userfield field="avatar" user="#me" /][/cb:else][/cb:if]

The above makes more sense and is easier to read what is happening as well so the usecase isn't technically gone, but it has been changed.

#2 Updated by beat 3 months ago

  • Target version changed from CB 2.4.4 to CB 2.5

#3 Updated by beat 3 months ago

  • Target version changed from CB 2.5 to CB 2.4.5

#4 Updated by beat about 1 month ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF