1

I'm getting into Stash and I wondered what the best way of handling tag pairs such as files/images?

My aim is to totally separate out the markup from the fetching of stuff from the database (exp:channel:entries tags etc). So far, this is how I'm currently handling it, and it works fine:

Model end of things (this would be within exp:channel:entries tag also with a load of other stuff).

{exp:stash:set_list name="main_image" parse_tags="yes"}
{my_image}
    {stash:url}{url}{/stash:url}
    {stash:height}{height}{/stash:height}
    {stash:width}{width}{/stash:width}
    {stash:title}{title}{/stash:title}
{/my_image}
{/exp:stash:set_list}

Markup end of things

{exp:stash:get_list name="main_image"}
<img src="{url}" height="{height}" width="{width}" alt="{title}" title="{title}" />
{/exp:stash:get_list}

What concerns me the most is I'm using a list even though there will only ever be one thing in it, as thus it makes me a bit uneasy.

Is there a better way of doing it? Like I said it definitely works, I just want to make sure I'm doing it right.

1 Answer 1

1

From a performance point of view I don't see anything wrong with that at all. It will still output your desired variables. The set_list tag pair ideally caters for an array of items (many) but it should be just as happy returning one.

You could just set them as regular stash:set variables but it shouldn't make any difference performance wise either way.

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.