This has been answered for visualforce, apex, html etc, but couldn't find anything for within a lightning markup.

<aura:attribute name="mode" type="String"/>
<aura:attribute name="selectedOption" type="String" default="{!if(v.mode == 'overlay', 'Closed', 'Open')}"/>

Now I need something like below so I could use pass it directly to a SOQL behind the scene:

<aura:attribute name="staticFilterCondition" type="String" default="{!'Status__c = \'' + v.selectedOption + '\''"/>

As you can see, the default value of staticFilterCondition attribute must be Status__c = 'Open' or Status__c = 'Closed' based on selectedOption. How to? I know this can be done via init, but wondering if there is a way to directly handle this in the markup?

I looked at the expression functions and tried below but no luck. Returns Status__c = Open

<aura:attribute name="staticFilterConditionPart1" type="String" default="Status__c = "/>
<aura:attribute name="staticFilterConditionPart2" type="String" default="'"/>
<aura:attribute name="staticFilterConditionPart3" type="String" default="{!concat(concat(v.staticFilterConditionPart1, staticFilterConditionPart2), v.selectedOption)}"/>
<aura:attribute name="staticFilterConditionPart4" type="String" default="'"/>
<aura:attribute name="staticFilterCondition" type="String" default="{!concat(v.staticFilterConditionPart3, staticFilterConditionPart4)}"/>
  • Even if it were possible, please put logic inside your doInit as it's pretty anti-pattern to place so much logic inside an attribute.
    – tsalb
    Jun 19, 2018 at 17:32

1 Answer 1


You'd have to "escape the escapes", meaning it should look more like:

<aura:attribute name="staticFilterCondition" 
                default="{!'Status__c = \\\'' + v.selectedOption + '\\\''}"/>

However, I don't think this will work, since the order of default initialization isn't specified, so there's no way to guarantee that v.selectedOption will be set before init (aura:valueInit) is fired. I would do so in the init function.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .