I'm using the LookupOrderedRows to populate an email with Apartment Suggestions.
Here's a simple version of the AMPscript:
%%[
var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i
set @lookupValue = AttributeValue("SA_City__c") /* value from attribute or DE column in send context */
set @numRowsToReturn = 0 /* 0 means all, max 2000 */
set @rows = LookupOrderedRows("FLTR_Apartment_Salesforce",@numRowsToReturn,"Price__c asc, Number_of_bedrooms__c, Cover_picture__c, Code__c, Available_From__c, Street__c, Country_Code__c, Number_of_allowed_residents__c, Enabled_Booking_Modes__c","City__c", @lookupValue)
set @rowCount = rowcount(@rows)
if @rowCount > 0 then
for @i = 1 to @rowCount do
set @row = row(@rows,@i) /* get row based on counter */
set @Price__c = field(@row,"Price__c")
set @Number_of_bedrooms__c = field(@row,"Number_of_bedrooms__c")
set @Cover_picture__c = field(@row,"Cover_picture__c")
set @Code__c = field(@row,"Code__c")
]%%
Row %%=v(@i)=%%<br>
Code %%=v(@Code__c)=%%<br>
Guests %%=v(@Number_of_allowed_residents__c)=%%<br>
Cover Picture %%=v(@Cover_picture__c)=%%<br>
Number of Bedrooms is %%=v(@Number_of_bedrooms__c)=%%<br>
Price %%=v(@Price__c)=%%<br><br>
%%[
next @i ]%%
%%[ else ]%%
No rows found
%%[ endif ]%%
What I want to do is basically replace the "No rows found" part with other AMPscript and HTML which will populate a "backup" apartment suggestion if the LookupOrderedRows function doesn't provide content.
I've tried this and the HTML loads, but the AMPscript doesn't. Example below:
...%%[next @i]%%%%[ELSE]%%
%%[
{{!-- apartment suggestion 1 --}}
SET @Cancellation_Flexibility__c_1 = AttributeValue("1_Cancellation_Flexibility__c")
SET @Cover_picture__c_1 = AttributeValue("1_Cover_picture__c")
SET @City__c_1 = AttributeValue("1_City__c")
SET @Enabled_Booking_Modes__c_1 = AttributeValue("1_Enabled_Booking_Modes__c")
]%%
<div class="apartment"><table><tr><td style="width: 50%; height: 100%; padding-right: 3px;" class="responsive-td" valign="top"><img style="vertical-align:middle"><a href="%%=v(@view_apartment_suggestion_1)=%%" title="apartment_suggestion_1" alias="apartment_suggestion_1" conversion="true" data-linkto="other"><img data-assetid="109550" src="%%=v(@1_Cover_picture__c)=%%" style="display: block; text-align: center; border-radius: 10px; padding: 5px; height: 200px; width: 270px;"></a></td>
<td style="line-height:1.2;padding: 10px;"><b>%%=v(@1_Street__c)=%%, %%=v(@1_Postal_Code__c)=%%, %%=v(@1_City__c)=%%</b><br><br>%%=v(@1_Cancellation_Flexibility__c)=%% %%=v(@1_Security_Deposit__c)=%% %%=v(@1_Enabled_Booking_Modes__c)=%%<br><br><span style="font-size:13px">up to %%=v(@1_Number_of_allowed_residents__c)=%% persons<span style="padding: 2px;font-size:11px;color:#ffffff;"> • </span>%%=v(@1_Number_of_bedrooms__c)=%% bedrooms<span style="padding: 2px;font-size:11px;color:#ffffff;"> • </span>%%=v(@1_Number_of_bathrooms__c)=%% bathrooms</span><br><br><table role="presentation" width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td align="left"><table role="presentation" cellspacing="0" cellpadding="0" border="0"><tr><td class="innertd buttonblock" style=" border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; background-color: #6699CC;" bgcolor="#6699CC"><a target="_blank" class="buttonstyles" style=" font-size: 16px; font-family: Arial, helvetica, sans-serif; color: #FFFFFF; text-align: center; text-decoration: none; display: block; background-color: #6699CC; border: 1px solid #6699CC; padding: 5px 40px; border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;" href="%%=v(@view_apartment_suggestion_1)=%%" title="View Apartment" alias="view_apartment_suggestion_1" conversion="false" data-linkto="other">View Apartment</a></td></tr></table></td></tr></table>
</td>
</table></div><br>%%[ENDIF]%%
How do I get the AMPscript to work in this case? Is there a function I should be using, such as Output()?
v
function which is better for your use case. Can you try removing that weird comment in curly brackets? Or replace the double curly brackets with the AMPscript comment tag/* apartment suggestion */