You need to sign in to do that
Don't have an account?

Rendering HTML in a VisualForce IF statement
This should be super-simple, I'm just not seeing how to fix this. I'd like to output HTML (a simple <br>) IF a certain condition is made. Here is a snippet of my code:
<apex:outputField value="{!facility.Facility_Address_1__c}" /> {! IF(facility.Facility_Address_2__c!='','<br/>','NOPE')} <apex:outputField value="{!facility.Facility_Address_2__c}" />
Basically, just want to output the first line of the address, if there is a second line to the address, add a new line break, then output the second line of the address. Instead of a new line break, all I get is straight text, "<br/>" is stuck between the two address lines.
I also tried using br() and HTMLENCODE to no avail...even tried moving the text concatenation to the controller...I'm so lost...
Try using an Apex:Output tag to create a span with br tag.
That might work better.
Dan GrandquistEtherios - Technical Architect
All Answers
Try using an Apex:Output tag to create a span with br tag.
That might work better.
Dan GrandquistEtherios - Technical Architect
Try using this...
Thanks Dan, that worked. But it seems like there might be a better solution if I need to output HTML, not text, in the future...right? I think eventually I'll need to understand how to make some HTML code from the controller...maybe?
Rambo, not sure you understood what I was getting at...that's what I had originally, but when there isn't a second address line (which quite frequently happens), I want the address to 'shrink up' and therefore don't need that <br/>...
As a best practice I try to avoid getting HTML markup from the controller. Now there are some times when you can't avoid it, like when you are using a web callout. But in those cases you should try to make those areas of the page well defined div or OutputField tags.
The real solution here depends on you layout:
In Salesforce Style layouts (those that use the Salesforce UI) - I use blank apex:pageBlockSectionItem with a render to line up UI components.
In Non-Salesforce Style layouts (those that need to look like the company Web site) - I use CSS to solve the problem, formatting the page div to line up correctly
Having coded HTML for a while, one thing I had to learn in this framework is to use the Salesforce tags to render the HTML I wanted and not try to fight the framework.
Thanks for the Solve,
-Dan
Thanks for the guidance. I'm still learning what to put where and thought in the future I might need to work some more complex logic through the controller, and therefore pass HTML to the VF page. But I guess maybe that is not necessary and I can get the logic from the VF components.
I know this is old, but cant you accomplish this using escape="false" in an outputText tag?
Yes escape="false" works well, I was able to use it as below -