Photo of Christopher Georges

0

Lava Attribute

I have been racking my brain for days trying to get this to work. I created a content channel type with an image attribute. I then created a content channel and added the image. but when I add the block to the page I don't see the attribute output. I even selected debug to see if I was missing something. Here's what my code looks like minus the html


{% for item in Items %}

{{ item.Link }}

{{ Items | Attribute:'BackgroundImage' }}

{{ item.Title }}

{% endfor %}


The item link and title show perfectly. But the background image won't show. What am I doing wrong?

  • Photo of Jim Michael

    0

    I think there are a couple of problems...  {{ Items | Attribute:'BackgroundImage' }} should be {{ item | Attribute:'BackgroundImage' }}, but you can't simply grab an image like that... you need to do something like this:

    {% assign image = item | Attribute:'BackgroundImage', 'RawValue' %}

    [img src="/GetImage.ashx?guid={{ image }}" class="img img-responsive" alt=""] (I used [ ] instead of < > in that code so it would render here)

    The gist is that you get the item attribute's guid and assign it to a variable, then use the GetImage.ashx functionality to grab the image with that guid. You'd also probably want to wrap it in a if statement to make sure the image variable isn't empty.

  • Photo of Christopher Georges

    0

    This helps a lot! How did you come up with this? Not sure if I saw any of this in the docs.

    • Jim Michael

      I think for that I learned it by looking at the default lava in the content channel view block on the podcast page of the default public Rock site. While the Rock docs are great, you'll find that every possible use of Lava isn't documented and you just have to learn by asking ;-)