Developer forum

Forum » CMS - Standard features » Query Publisher with a String array

Query Publisher with a String array

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

I created an index builder extender saving a string array. Now using the QueryPublisher I am not able to use the values saved there. How could I get using standard tags?

 

Best Regards,

Nuno Aguiar


Replies

 
Nicolai Pedersen
Reply

Hi Nuno

I do not understand.

BR Nicolai

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

Here's what I mean. And I made a few tests as well so I have it working as I need it, I just want to understand what to expect out of the platform:

 

I created the field as String array https://www.screencast.com/t/wVQ5fQ8OKWH. I was expecting to do something like:

var fileDescriptions = item.GetValue("FileFriendlyName");

foreach (var description in fileDescriptions) {

...

}

 

The output though is not an array (because DW's template engine does not return string arrays) https://www.screencast.com/t/evuKGy8DsE. And now that I spell this out I kind of realize I would never get this, unless it would be converted into a Loop.

 

So I guess my question now is:

  • Should I expect this to ever come back as a Loop? Or would in the future, moving towards ViewModels get this as a proper string array?

 

Best Regards,

Nuno Aguiar

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Nuno

It is returned as system.object containing the type that is in the index, in this case a string array - so you get a string array from GetValue - so no loop.

Here is a sample from the default template - you should be able to use that.

@foreach (var result in GetLoop("QueryResultItem"))
    {
        <li class="result-item">
            <table>
                @foreach (var prop in result.GetLoop("Properties"))
                {
                    <tr>
                        <td class="name">@prop.GetValue("Name")</td>
                        <td class="value">
                            @prop.GetValue("Value")
                            @{
                                if (prop.GetValue("Value").GetType() == typeof(bool[]))
                                {
                                    <br />
                                    foreach (bool b in (bool[])prop.GetValue("Value"))
                                    {
                                        <text>@b.ToString()<br /></text>
                                    }
                                }
                                if (prop.GetValue("Value").GetType() == typeof(String[]))
                                {
                                    <br />
                                    foreach (string s in (String[])prop.GetValue("Value"))
                                    {
                                        <text>@s<br /></text>
                                    }
                                }
                            }
                        </td>

                    </tr>
                }
            </table>
        </li>
    }

Votes for this answer: 2
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

Gotcha, thanks for showing me that. I'll bookmark it in my documentation ;)

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum