PDA

View Full Version : Array to String


badbeer
07-29-08, 12:51 AM
I want to take an array and convert into a string that I call elsewhere on a page. I have Toolkit but, I'm not clear as to the best way to accomplish this.

For example, a listing of sub categories converted to a string. Call the string variable into an HTML tag or javascript.

Ideas, suggestions, general flames?

wcw
07-29-08, 01:02 AM
Look at the concat function in the module's admin screen.

badbeer
07-29-08, 01:43 AM
I was looking at that but there isn't any example other than the syntax. With the below, I want to concantenate all of the sub_cats into one variable. I've been guessing since there wasn't any explaination and don't know what to do with the other variable.

<mvt:if expr="l.settings:sub_cats">
<mvt:foreach iterator="subcat" array="sub_cats">
<mvt:item name="toolkit" param="concat|newstring|var|&mvt:subcat:name;" /> ???
</mvt:foreach>
</mvt:if>

and assuming that the above works, to call the string would be later in the page would be:

&mvte:global:newstring ?

wcw
07-29-08, 01:48 AM
Look at the vrandom function. There is an example which uses the concat function to build a string which is then used to display a random product. You would change the product code for the category name.

Also, you can never use &mvt inside any item tag in merchant. See the vrandom example at #36 at http://www.emporiumplus.com/go/wcw/PROD/1AA/1AA00223

badbeer
07-29-08, 03:28 AM
My problem now, I believe is knowing what to put in as the sub-cat variable. If I can get this to work, I can add the rest of the conditionals for integration. I don't know the Miva variable structure though I tried to look it up in the docs.

<mvt:foreach iterator="sub_category" array="sub_categories">
<mvt:item name="toolkit" param="concat|newstring|newstring|l.settings:sub_cats:nam e" />
</mvt:foreach>
<p>&mvte:global:newstring;</p>

wcw
07-29-08, 03:33 AM
It depends on your array. If the iterator is sub_category it might be something like l.settings:sub_category:name or maybe with l.all_settings You should be using latu's free store helper to see what variables are on each page.

badbeer
07-29-08, 05:21 AM
The the array was stated in my previous post and was first stated in post #3 - the sub category listing. I was looking for an exact answer since I've attempted many variations already.

wcw
07-29-08, 05:42 AM
Did you try my two suggestions?

For example:

<mvt:item name="toolkit" param="subcat|ccount|g.Category_Code" />
<mvt:if expr="ccount GT 0">
<mvt:foreach iterator="sub_category" array="sub_categories">
<mvt:item name="toolkit" param="concat|newstring|newstring|l.all_settings:sub_cate gory:name" />
</mvt:foreach>
TEST: &mvte:global:newstring;
</mvt:if>

badbeer
07-29-08, 01:35 PM
Yes, I tried both before my last post with about 6 other combinations. Just to be certain, I tried them again and your two guesses didn't work.

wcw
07-29-08, 02:11 PM
The example I posted works in my store. Are you sure you have a version of the tool kit that includes the concat function? Perhaps you have an old version. Look at the module's admin screen and see if concat is there. If it is, then your array is not right. Put &mvte:sub_category:name; to see if the names display.

badbeer
07-29-08, 04:18 PM
The array was not right. It got changed from post #1 to later posts apparently from all the trials I was performing. The below is the simplified version for stuffing the meta description tag when on a category page just in case someone else wants it.

<mvt:item name="toolkit" param="sassign|delimiter|, " />
<mvt:foreach iterator="sub_category" array="sub_cats">
<mvt:item name="toolkit" param="concat|newstring|newstring|l.all_settings:sub_cate gory:name" />
<mvt:item name="toolkit" param="concat|newstring|newstring|delimiter" />
</mvt:foreach>
<meta name="Description" content="Category Sub-Categories: &mvte:global:newstring;">