2

EE 2.10.1 Lv 2.6.1 Assets 2.6

I've got a Low Variables grid with a once cell Assets and in the assets you can upload multiple images.

Using this thread I was able to successfully display a single image, but there is no way to loop through the assets to pull up all files.

My current partially working code looks like this where title, image, and copy or cells in the grid.:

        {exp:low_variables:pair var="lv-deal-sidebar-widget"}
            <aside>
                <h3>{lv-deal-sidebar-widget:title}</h3>

                {exp:ce_img:single src="{lv-deal-sidebar-widget:image:url}" width="300" height="240" crop="yes" attributes="class='img-responsive'"}

                <div class="widget-copy">
                    {lv-deal-sidebar-widget:copy}
                </div><!-- /.widget-copy -->
            </aside>
        {/exp:low_variables:pair}

If I try to get more than one image using this thread as a guide and this simplified code:

        {exp:low_variables:pair var="lv-deal-sidebar-widget" var_prefix="assets"}
            <aside>

                <p>{lv-deal-sidebar-widget:image:url}</p>

                {assets:image}
                    {assets:url} <br />
                {/assets:image}

            </aside>
        {/exp:low_variables:pair}

the assets pair doesn't render it just outputs the code as is. Any ideas on how to fix this?

2 Answers 2

2

I reported this bug to Pixel & Tonic, and they right away got working on a "duct-tape" type fix. It seems, to get this working, in Assets 2.6, you can change line 1810 of system/expressionengine/third_party/assets/ft.assets.php from

if (! $field_name)

to

$tagparts = ee()->TMPL->tagparts;
if (! $field_name || (isset($tagparts[0]) && $tagparts[0] == 'low_variables'))

and then in your template, you need to use the var_prefix parameter, and then put that prefix BEFORE everything else in your variable, and it should look something like this:

{homepage_slider:images var_prefix="image"}
    <img src="{image:homepage_slider:images:url}" />
{/homepage_slider:images}

Hope this helps someone!

1
  • 1
    Will try this later, but hope it gets added to a new assets build soon. Not a fan of using hacks.
    – CreateSean
    Feb 19, 2016 at 15:11
1

When using the Parse or Pair tag to output a Grid field, the tag will act the same as a regular Channel Grid field would. That means you can use the same template tags and parameters. That means the var_prefix parameter won't do anything, because it's not a valid Grid parameter.

It also means you need to prefix all Grid columns with the field/var name. So rather than using {assets:image}{/assets:image}, you should use what you're already using with the title column: {lv-deal-sidebar-widget:image}{/lv-deal-sidebar-widget:image} (assuming image is the name of the Assets column in Grid).

That, in turn, will act the same as a regular Assets field, so you should be able to use any of its template tags.

Edit: To illustrate:

{!-- a LV Grid with Assets column --}
{exp:low_variables:pair var="my_grid_var"}
    {my_grid_var:assets_column_name var_prefix="foo"}
        {foo:my_grid_var:assets_column_name:url}
    {/my_grid_var:assets_column_name}
{/exp:low_variables:pair}

{!-- an Assets var --}
{exp:low_variables:pair var="my_assets_var"}
    {url}
{/exp:low_variables:pair}
10
  • I've done that but it doesn't work. If I use the tag pair you posted with {url} in the middle front end outputs two {url}{url} but it's not the url just the code. same if I use {image:url} but if I put {lv-deal-sidebar-widget:image:url} then I get one url not two as expected.
    – CreateSean
    Jan 14, 2016 at 14:55
  • The fact that it spits out two {url} vars tells me the loop does work, but you just need to get the variable naming right. See my examples that I just added. Perhaps that sheds some light. Also note that LV is not responsible for parsing the Grid/Assets vars. It just calls their functions and returns what they return.
    – Low
    Jan 14, 2016 at 15:01
  • copied exactly what you have and it's still outputting {foo:url} twice See this pastie pastie.org/10689796
    – CreateSean
    Jan 14, 2016 at 15:05
  • Well, it was untested. ;) Ask P&T.
    – Low
    Jan 14, 2016 at 15:06
  • 1
    that didn't work, I'd already tried before you posted. In anycase I tweeted this thread to P&T. Thanks for your time.
    – CreateSean
    Jan 14, 2016 at 16:00

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.