Question

Photo of Jackie Powers

0

AdRotator and Variables

I'm not sure if this should go in web development or here so if it belongs in web development, I'm sorry.

I added a link attribute to my content channel items so I can specify what page displays when the picture is clicked. However, I want to make it either go to the specified link or the detail page for that particular item, so I have created a few variables and tried that way. However, I cannot get my link variable to initialize properly. Is it possible to initialize a variable with another variable in Lava? If so, what have I done wrong? Here is the code I've written. linkable and detailPage do what they are intended to do (I've put those variable in the <a> instead of link). So, my issue is with the link variable. Here is the code I'm working with.



{% capture linkable %} {{ item | Attribute:'Link' }} {% endcapture %}

{% capture detailPage %}{{ LinkedPages.DetailPage }}?Item={{ item.Id }}{% endcapture %}

{% if linkable == 'default' %}

{% assign link = detailPage %}

{% else %}

{% assign link = linkable %}

{% endif %}

<a href="{{ detailPage }}">{{ item | Attribute:'Image' }}</a>






  • Photo of Nate Hoffman

    0

    Hi Jackie,

    Mine is similar code, I am not sure why yours wouldn't work appropriately, mine does use RawValue due to using the actual "link" type for the attribute, but if you want to look at mine and tweak yours similar this is what I use:

    {% assign redirectURL = item | Attribute:'RedirectURL','RawValue' %}

    {% assign detailURL = '' %}

    {% if redirectURL and redirectURL != empty %}

    {% assign detailURL = redirectURL %}

    {% else %}{% capture detailURL %}

    {{ LinkedPages.DetailPage }}?Item={{ item.Id }}{% endcapture %}

    {% endif %}

    <a href="{{ detailURL }}">{{ item | Attribute:'Image' }}</a>

    • Jackie Powers

      Thank you! I ended up using capture instead and that solved my issue but yours seems much simpler so I may modify it to fit my variables.