croxton / Stash

Stash allows you to stash text and snippets of code for reuse throughout your templates.
GNU General Public License v3.0
197 stars 20 forks source link

List items missing when appending multiple items with append_list #101

Closed timkelty closed 10 years ago

timkelty commented 10 years ago
{exp:stash:set_list
  name="js"
}
  {stash:src}I should be last{/stash:src}
  {stash:priority}100{/stash:priority}
{/exp:stash:set_list}

{exp:stash:append_list
  name="js"
}
  {stash:src}/assets/vendor/labjs/LAB.src.js{/stash:src}
  {stash:priority}0{/stash:priority}

  {stash:src}//code.jquery.com/ui/1.10.3/jquery-ui.js{/stash:src}
  {stash:priority}10{/stash:priority}
{/exp:stash:append_list}

{exp:stash:get_list
  name="js"
  orderby="priority"
  sort="asc"
}
  <script src="{src}"></script>
{/exp:stash:get_list}

Result (missing jquery-ui) :

  <script src="/assets/vendor/labjs/LAB.src.js"></script>
  <script src="I should be last"></script>

Strangley enough, if I change the second append_list to a set_list and add append="yes", it gets even weirder:

  <script src="I should be last"></script>
  <script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

Should this work, or do you always have to do one at a time when using append_list?

croxton commented 10 years ago

append_list and 'prepend_list` only allow you to add one "row" at a time; they're meant to be used inside loops.

You can however join two or more lists (each with as many rows as you like but all lists must share the same keys) with join_lists.

{exp:stash:join_lists name="my_combined_list" lists="list_1,list_2,list3"}
croxton commented 10 years ago

I have documented that yet btw.

timkelty commented 10 years ago

Ok, figured that was the case.

This approach seems to work and be the cleanest approach (this of course would make more sense when the tags were split up to their appropriate view/model templates: EE Template:

{exp:stash:set_list
  name="js"
}
  {stash:src}I should be last{/stash:src}
  {stash:priority}100{/stash:priority}
{/exp:stash:set_list}

Layout viewModel:

{exp:stash:set_list
  name="global_js"
}
  {stash:src}/assets/vendor/labjs/LAB.src.js{/stash:src}
  {stash:priority}0{/stash:priority}

  {stash:src}//code.jquery.com/ui/1.10.3/jquery-ui.js{/stash:src}
  {stash:priority}10{/stash:priority}
{/exp:stash:set_list}

{exp:stash:join_lists name="js" lists="global_js,js"}

Layout view:

{exp:stash:get_list
  name="js"
  orderby="priority"
  sort="asc"
}
  <script src="{src}"></script>
{/exp:stash:get_list}
croxton commented 10 years ago

Indeed. Clever use case there too, I like it.

timkelty commented 10 years ago

And the join_lists seems to behave if js isn't set, so that's good.

timkelty commented 10 years ago

Works well! And then acutally I wrap the layout in a minimee tag as well:

      {exp:minimee:js}
        {exp:stash:get_list
          name="js"
          orderby="priority"
          sort="asc"
        }
          <script src="{src}"></script>
        {/exp:stash:get_list}
      {/exp:minimee:js}
croxton commented 10 years ago

Awesome!