Foren

RE: WCM Freemarker - Get Title

thumbnail
Jacob Caniparoli, geändert vor 10 Jahren.

WCM Freemarker - Get Title

Junior Member Beiträge: 27 Beitrittsdatum: 22.06.10 Neueste Beiträge
Hi All,

I am looking into freemarker templating in Liferay 6.2. I would like to access the default title field in my template. If I create my own "Title" field using a structure, I can access that variable using this line:

${title.getData()}

That is fine, but there is already a "Title" field by default when creating web content, so I would much rather access that. How do I get it?

Thanks,
Jacob
thumbnail
Jacob Caniparoli, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Junior Member Beiträge: 27 Beitrittsdatum: 22.06.10 Neueste Beiträge
Nevermind, this question has already been posted and answered.

The answer is:
${.vars['reserved-article-title'].data}


This is the original post
thumbnail
Pankaj Kathiriya, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Liferay Master Beiträge: 722 Beitrittsdatum: 05.08.10 Neueste Beiträge
Use $reserved-article-title .
thumbnail
Jacob Caniparoli, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Junior Member Beiträge: 27 Beitrittsdatum: 22.06.10 Neueste Beiträge
Pankaj Kathiriya:
Use $reserved-article-title .


I cannot see a way to make this work. My example above DOES work, however.

As a partial aside, is there some kind of documentation somewhere that would let me know these other variables that are available?

Thanks,
Jacob
thumbnail
James Falkner, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
Jacob Caniparoli:
Pankaj Kathiriya:
Use $reserved-article-title .


I cannot see a way to make this work. My example above DOES work, however.

As a partial aside, is there some kind of documentation somewhere that would let me know these other variables that are available?

Thanks,
Jacob


It can't ever work, because the variable has a dash in its name - and Freemarker interprets it as the mathematical subtraction operator (that's why you have to use the "vars" variable to access those special variables).

The full list can be found here.
thumbnail
Pankaj Kathiriya, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Liferay Master Beiträge: 722 Beitrittsdatum: 05.08.10 Neueste Beiträge
I meant to say $reserved-article-title.getData()
,I have used this way and found working fine.
thumbnail
James Falkner, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
Pankaj Kathiriya:
I meant to say $reserved-article-title.getData()
,I have used this way and found working fine.


Yeah, that works in Velocity, just not in Freemarker.
thumbnail
Rohan Deshpande, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

New Member Beiträge: 3 Beitrittsdatum: 18.02.13 Neueste Beiträge
Can anyone tell me how can I access ThemeDisplay object in freemarker WCM template in Liferay 6.2

Thanks
thumbnail
James Falkner, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
Rohan Deshpande:
Can anyone tell me how can I access ThemeDisplay object in freemarker WCM template in Liferay 6.2

Thanks


Here's an example of how to retrieve the Real User ID in a WCM Freemarker template:
${request['theme-display']['real-user-id']}
Note that the Theme Display object isn't an instance of the com.liferay.portal.theme.ThemeDisplay class (like it is when you are creating a Theme template). Instead it's a Map of common and serializable elements from the ThemeDisplay interface, like the Real User ID (in this example).
thumbnail
Rohan Deshpande, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

New Member Beiträge: 3 Beitrittsdatum: 18.02.13 Neueste Beiträge
James Falkner:
Rohan Deshpande:
Can anyone tell me how can I access ThemeDisplay object in freemarker WCM template in Liferay 6.2

Thanks


Here's an example of how to retrieve the Real User ID in a WCM Freemarker template:
${request['theme-display']['real-user-id']}
Note that the Theme Display object isn't an instance of the com.liferay.portal.theme.ThemeDisplay class (like it is when you are creating a Theme template). Instead it's a Map of common and serializable elements from the ThemeDisplay interface, like the Real User ID (in this example).


Thanks James.

In 6.1.2 we have FreemarkerVariables and VelocityVariables interfaces which were useful to find the variables. I could not find these classes in 6.2

Could you please let us know how where can we find those details in 6.2 so that we can easily figure out different variables accessible in WCM templates.

Cheers
thumbnail
James Falkner, geändert vor 10 Jahren.

RE: WCM Freemarker - Get Title

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
Rohan Deshpande:
James Falkner:
Rohan Deshpande:
Can anyone tell me how can I access ThemeDisplay object in freemarker WCM template in Liferay 6.2

Thanks


Here's an example of how to retrieve the Real User ID in a WCM Freemarker template:
${request['theme-display']['real-user-id']}
Note that the Theme Display object isn't an instance of the com.liferay.portal.theme.ThemeDisplay class (like it is when you are creating a Theme template). Instead it's a Map of common and serializable elements from the ThemeDisplay interface, like the Real User ID (in this example).


Thanks James.

In 6.1.2 we have FreemarkerVariables and VelocityVariables interfaces which were useful to find the variables. I could not find these classes in 6.2

Could you please let us know how where can we find those details in 6.2 so that we can easily figure out different variables accessible in WCM templates.

Cheers


Yes, these classes have been refactored/improved/changed in 6.2, so it's not easy to see all the variables by inspecting code.

Instead, what I have done is create a utility template (Freemarker) which will dump out all of the available variables (and their values, if they are simple values like strings, dates, and numbers), or a list of method names for the variable in the case of variables which are classes.

To use it, simply cut and paste this freemarker code into a template for a web content article, and view it. It iterates over all of the available variables, and prints out their values and/or methods. In addition, at the bottom, it does a complete expansion of the request object, which contains a lot of useful stuff in it. Check out the below screenshot for an example.

Kudos to Chaquotay for the code. I had to modify it because if you try to do a deep expansion of everything (i.e. the .data_model special variable), it sets your server on fire as it recursively tries to expand everything in the universe.
thumbnail
Rohan Deshpande, geändert vor 9 Jahren.

RE: WCM Freemarker - Get Title

New Member Beiträge: 3 Beitrittsdatum: 18.02.13 Neueste Beiträge
I want to access the Layout details.

request["attributes"]['LAYOUT'] gives me string representation which looks something like this

"{uuid=fbb92a8e-ccbc-4b18-af8f-ac67332d39e5, plid=95301, groupId=10184, companyId=10157, userId=10701,.......}"


How would I access uuid from this?

As its a string representation
request["attributes"]['LAYOUT']['uuid']
does not work.