Find your content:

Search form

You are here

Dynamically populate title based on description

 
Share

I am working on a full customer portal but have run into a slight issue. I have to put a title on every page that is dynamic and can easily be changed by someone who does not code. I would like to simply display whatever is in the description box for that page. Using Force Explorer I was able to create a query using the Visualforce Page label,

SELECT Description, Name FROM ApexPage Limit 10

I pulled the name also so I could verify the pages easily. The problem is I am not able to add this to my VF pages. Currently I have,

<head>
  <title>{!$ApexPage.Description}</title>
</head>

But I get an error message saying that the field does not exist. Does anyone know how to render this field without using any type of controller?


Attribution to: Grady D

Possible Suggestion/Solution #1

My most likely Visualforce global candidate would be $CurrentPage but this page:

<apex:page>
    {! $CurrentPage.Name }
    {! $CurrentPage.URL }
    {! $CurrentPage.Description }
</apex:page>

produces a:

Field Description does not exist.

error at compile time. So I think you are probably out of luck (without a controller).


Attribution to: Keith C

Possible Suggestion/Solution #2

Great idea, love the reuse! I've tried $Page.pageName.Description and $CurrentPage.Description both result in failures to save the page, so it seems we are out of options in respect to reusing the Description. However we are not yet out of code free options, given your original requirement....

  • Custom Setting. Create a Hierarchy Custom setting (under Setup > Develop) and add fields for each page (it would help to name them consistently with the page name). Then in each of your pages you can reference these without code via {!$Setup.PageDescriptions__c.page1__c}. This also btw has the nice side effect of allowing you to customise the description based on the user or profile!
  • Custom Labels. Under the Create menu you will find Custom Labels, these can also be referenced without code in your Visualforce pages, and can also be translated into multiple languages (something the above and ApexPage Description routes cannot do). You can create Custom Labels based again on the name of your pages and also categorise them in order to create a List View to access them easily amongst others. The syntax would be {!$Label.page1} for example.

Given the two options, the Custom Label route gets my vote because it feels more aligned with your needs, though the ability to customise by user or profile might be appealing, that said, there is no reason why you cannot combine both...

Hope this helps!


Attribution to: Andrew Fawcett
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32657

My Block Status

My Block Content