Foren

[RESOLVED] How to display the value of a String in Velocity Template

Mike Harris, geändert vor 11 Jahren.

[RESOLVED] How to display the value of a String in Velocity Template

Junior Member Beiträge: 91 Beitrittsdatum: 28.03.11 Neueste Beiträge
I'm using this to display a custom field of a page in a velocity template :

  #set ($customField= $layout.getExpandoBridge().getAttribute("CustomFieldKey"))
  CustomFieldKey= $customField


This works but it's displaying the object's memory address like [Ljava.lang.String;@6842333]
How can I display it's value?

I tried $customField.toString() (same thing)
or
#set ($customField= (String)$layout.getExpandoBridge().getAttribute("CustomFieldKey"))
doesn't work either
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: How to display the value of a String in Velocity Template

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
[Ljava.lang.String] means it's an array of strings, not a simple string.

Try $customField[0]
Mike Harris, geändert vor 11 Jahren.

RE: How to display the value of a String in Velocity Template

Junior Member Beiträge: 91 Beitrittsdatum: 28.03.11 Neueste Beiträge
This doesn't work for me.
It shows the same thing with the index after like :
[Ljava.lang.String;@5d8280c7[0]

emoticon
Mike Harris, geändert vor 11 Jahren.

RE: How to display the value of a String in Velocity Template

Junior Member Beiträge: 91 Beitrittsdatum: 28.03.11 Neueste Beiträge
Here's what I tried... Nothing of these works:

#set ($customField = $layout.getExpandoBridge().getAttribute("CustomField"))

<br>Test 1 : $customField.get(0)

#set($customField2 = $customField .get(0))
<br>Test 2 : $customField2

<br>Test 3 : $customField [0]

#set($customField4 = $customField[0])
<br>Test 4 : $customField4

(test 4 gives me a stack trace)
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: How to display the value of a String in Velocity Template

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
According to this, the $customField[0] should work.
Mike Harris, geändert vor 11 Jahren.

RE: How to display the value of a String in Velocity Template

Junior Member Beiträge: 91 Beitrittsdatum: 28.03.11 Neueste Beiträge
Well, it never worked... I used a foreach instead like this :

#set ($testItems = $page.getExpandoBridge().getAttribute("Custom Field Name"))

#set ($myVar = 'Default value')

#foreach( $testItem in $testItems)
#set ($myVar = $testItem )
#end

$myVar
thumbnail
Daniel Carrillo Broeder, geändert vor 7 Jahren.

RE: [RESOLVED] How to display the value of a String in Velocity Template

New Member Beiträge: 5 Beitrittsdatum: 28.07.15 Neueste Beiträge
You could also use $customField.get(0)