Developer forum

Forum » CMS - Standard features » Print out values of System.String[] array

Print out values of System.String[] array

Lars Pham
Reply

I've created an index in repositories that indexed all content (pages, paragraps) and I get this. 

 ParagraphContent System.String[]  

Which by your documentation should contain:

  • Paragraph content contains an array of the item type properties for each item-based paragraph on a page

How do I print out the values of said array? 

I've tried the solution from here: https://doc.dynamicweb.com/forum/cms-standard-features/cms-standard-features/how-can-i-get-and-publish-value-of-a-system-string 

But with no luck. 


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply
This post has been marked as an answer

Hi Lars,

I was struggling with the same thing earlier today.

You have to Cast it first as a String[]:

I believe it is something like this (I am not 100% sure the syntax is right):

String[] yourVariable = (String[])GetValue("ParagraphContent");

Then, you should be able to do:

foreach(var arrayElement in yourVariable){

<text>@arrayElement</text>

}

Adrian

Votes for this answer: 1
 
Nicolai Pedersen
Reply

Also remember to mark the field as stored and not only indexed.

BR Nicolai

 
Lars Pham
Reply

Thanks Adrian! 

Your solution worked for me :) 
For anyone interested, this is what I came up with using the Query Publisher module. 

@foreach (var result in GetLoop("QueryResultItem")){
  <div class="result-item">
@{
       String[] Items = (String[])result.GetValue("ParagraphContent");
}
      <ul>
@foreach(var item in Items){
  <li>@item</li>
}
  </ul>
   </div>
}

 

You must be logged in to post in the forum