• Resolved benjamen02

    (@benjamen02)


    Hi there, I’m struggling to access a parameter in the query, set this value and then use it in the fetch condition. I have followed the forums but am still stuck

    I’m wanting to navigate to https://ads.adon.co.nz/?deviceid=Test which will send the parameter deviceid with the value of Test to the page with the following fetch/twig statement (note if I dont use the parameter and just hardcore the value of Test the codes runs)

    {% set devicename = query.params[‘deviceid’] %}
    {% fetchxml collection=”customers” cache=”PT30M” %}
    <fetch mapping=’logical’ returntotalrecordcount=’true’>
    <entity name=”cr152_ad”>
    <attribute name=”cr152_adid” />
    <attribute name=”cr152_name” />
    <attribute name=”cr152_width” />
    <attribute name=”cr152_imageurl” />
    <attribute name=”cr152_height” />
    <attribute name=”cr152_adqueue” />
    <attribute name=”cr152_account” />
    <order attribute=”cr152_name” descending=”false” />
    <filter type=”and”>
    <condition attribute=”statecode” operator=”eq” value=”0″ />
    </filter>
    <link-entity name=”cr152_adqueue” from=”cr152_adqueueid” to=”cr152_adqueue” link-type=”inner” alias=”ae”>
    <link-entity name=”cr152_device” from=”cr152_adqueue” to=”cr152_adqueueid” link-type=”inner” alias=”af”>
    <filter type=”and”>
    <condition attribute=”cr152_name” operator=”eq” value=”{{ devicename }}” />
    </filter>
    </link-entity>
    </link-entity>
    </entity>
    </fetch>
    {% endfetchxml %}
    {% if customers.results.entities|length > 0 %}

      {% for customer in customers.results.entities %}

    • {{customer[“cr152_name”]}}
    • {% endfor %}

    {% else %}
    No ads found.

    {% endif %}

    I’m using the Dataverse Gutenberg block

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author alexacrm

    (@alexacrm)

    @benjamen02

    the twig looks fine. What do you see if you simply do

    {% set devicename = query.params['deviceid'] %}
    <p>{{ devicename }}</p>

    Do you get Test in your output?

    The other quick check is to spit the xml that is actually sent to the server.

    {{customers.xml}}

    Actually, just noticed. Your quotes around deviceid look suspicious, they are ‘’ (smart quotes) while what you need is ” (straight quotes).

    • This reply was modified 2 years, 11 months ago by alexacrm.
    Thread Starter benjamen02

    (@benjamen02)

    If i just put the following the Dataverse Gutenberg block i get nothing:

    {% set devicename = query.params[‘deviceid’] %}
    <p>{{ devicename }}</p>

    https://ads.adon.co.nz/fetch/?deviceid=1

    Am I missing something basic here?

    I have check the {{customers.xml}} and the fetch is correct but it does not pick up the devicename variable

    Thread Starter benjamen02

    (@benjamen02)

    Sorted it – The code should be {% set devicename = request.params[‘deviceid’] %}
    Not query.params…whoops

    Plugin Author alexacrm

    (@alexacrm)

    @benjamen02 good find – missed it as well 😀

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Access URL parameter within Fetch Statement’ is closed to new replies.