Patrick Cornelissen
Patrick Cornelissen

Reputation: 7958

How to access custom fields of a page in the theme template

I'd like to use custom fields to display some page specific strings in the theme.

I have created a custom field "intro" of type Textbox.

How do I access the data in the theme template (velocity)?

As there is no "introspection" which variables are declared, I find it very difficult to figure out how to access them. The documentation is far from usable on the topic of custom fields :-/

Upvotes: 3

Views: 10054

Answers (3)

Wilson Delgado
Wilson Delgado

Reputation: 3

Work for me in Liferay 7+:

Create a custom field type "site", fill data into site settings, and use into theme template for call this data into liferay theme:

If a VM file:

#set ($site_custom_field = $layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key"))
<h1>$site_custom_field</h1>

If a FTL file:

<#assign site_custom_field = layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key")>
<h1>${site_custom_field}</h1>

Have a nice day!

Upvotes: 1

horelvis
horelvis

Reputation: 124

if you need use in template FTL, in my case for menu navigation template

<#assign prop = navItem.getLayout().getExpandoBridge().getAttribute("prop_name") >

Upvotes: 1

Martin Gamulin
Martin Gamulin

Reputation: 3865

If you definde custom attribute in a page than you can use

$layout.getExpandoBridge().getAttribute("intro")


Also see javadoc or source for com.liferay.portlet.expando.model.ExpandoBridge

Upvotes: 7

Related Questions