0

I try to understand better Stash Bundles, so I tried to use Stash code to save a group of variables as a single variable in a defined bundle.

The variables:

{exp:stash:set_value name="un" bundle="default"}
{exp:stash:set_value name="deux" bundle="default"}
{exp:stash:set_value name="trois" bundle="default"}

The group of the variables inside a defined bundle:

{exp:stash:bundle name="bundle"}
        {exp:stash:get  name="un"}
        {exp:stash:get  name="deux"}
        {exp:stash:get  name="trois"}
{/exp:stash:bundle}

Call the defined bundle

{exp:stash:get name="bundle"}

Results (in the html page):

a:3:{s:2:"un";N;s:4:"deux";N;s:5:"trois";N;}

Why the variables appears like this, and not display:

un
deux
trois

What it means a:3:{s:2: ;N; ? I'm totally lost. How to display only un deux trois?

Thanks.

Additional information.

I tried with:

http://site/stash/bundles

    {exp:stash:bundle name="segments"}
            {exp:stash:get name="{segment_1}"}
            {exp:stash:get name="{segment_2}"}
    {/exp:stash:bundle}

   <h1>{exp:stash:get name="segments"}</h1>

Results:

a:2:{s:5:"stash";N;s:7:"bundles";N;}

So a is the number of variables into a bundle, S: the number of characters of each variables. What is N ? I do not understand this output format, it seems as JSON. What can I do with this output:

a:2:{s:5:"stash";N;s:7:"bundles";N;} ?

How to use it, and only extract stash, bundles data, coming from {segment_x} ?

1 Answer 1

1

In my opinion, you are confusing bundles with lists. Stash lists will provide the functionality you're looking for (which is basically to group variables into an array). Bundles are merely used as a way of tagging variables and/or lists so they can be cache-busted independently.

Follow the examples in the documentation for set_list: https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Aset_list%7D

... and get_list: https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Aget_list%7D

3
  • Hi James. Thank you for your explanation. Yes, there was a confusion between bundles and lists. Now I understand better, but why bundles give this results: a:2:{s:5:"stash";N;s:7:"bundles";N;} . How to process this output format ?
    – Stéphane
    Mar 27, 2017 at 17:29
  • 1
    The format you're seeing is a serialized array. You won't ever need to process it manually. Use get_list and it processes it for you. You were seeing it because you were trying to output an array directly instead of its children Mar 28, 2017 at 10:50
  • Thanks a lot James for your good explanation , now my doubts are gone :). Regards, Stéphane
    – Stéphane
    Mar 28, 2017 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.