3

I am wondering if there's a way to dynamically render the title in the pageblock- something like this:

<apex:pageblock title="{!account.name}"> </apex:pageblock>

From the visualforce components documentation, it doesn't seem like it's something do-able. It seems to like it's a simple thing that salesforce should be able to do.

Cheers!

2

It is do-able. The expression language works AFAIK pretty much everywhere including the title attribute in your example. The documentation examples typically show only the most basic use.

|improve this answer|||||
  • Hi Keith, you are right. I believe my issue emanated from the fact that I my controller is a custom controller but I typed it in as if I was using a standard controller. Thanks for your input. – sw6 - KTBFFH Oct 1 '13 at 13:54
1

I haven't tried it in practice, but you might be able to do something with an apex:facet.

E.g. where showTitle is a property in the controller that returns a boolean indicating if the title should be rendered.

<apex:pageblock>
     <apex:facet name="header">
         <apex:outputText value="{!account.name}" rendered="{!showTitle}" />
     </apex:facet>
</apex:pageblock>

From the title documentation:

Note that if a header facet is included in the body of the pageBlock component, its value overrides this [the title] attribute.

Failing that, just wrap account.name in another controller property or method and bind to that instead. The new property or method could return null or an empty string if it should be hidden.

|improve this answer|||||
  • 1
    Only header and footer facets are documented for apex:pageBlock. – Keith C Oct 1 '13 at 10:08
  • @KeithC Whoops, yes. I've fixed the facet name to be "header" and added the documentation that it overrides the title attribute. – Daniel Ballinger Oct 1 '13 at 18:32
  • Cool. Didn't realize you could add content (presumably made of multiple elements if needed) to a apex:pageblock that way. – Keith C Oct 1 '13 at 19:42
  • I've used it to style the header for an apex:pageBlockSection in the past. Haven't tried to make it optionally disappear yet. – Daniel Ballinger Oct 1 '13 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.