modx-revolution

Create if condition with modx UrlParam


I got the value of the urlParam "image". No i want to show an image only if the Param is 1.

[[getUrlParam? &name=`image` &int=`1`]]

How can i do that?


Solution

  • You can use MODX output filters to achieve this.

    Using the output filters (:eq and :then) you can show the image as you wish. The output of the getUrlParam snippet is automatically submitted to the output filter :eq which then checks the desired value.

    Please make sure that you use an uncached snippet call in this case ([[!getUrlParam...]]) because you are dealing with data that changes every time the page is re-rendered/called. If you fail to do this the value of the GET variable will be cached after the first page call which will lead to inconsitencies in your desired result.

    [[!getUrlParam:eq=`1`:then=`<img src="/foobar.png" alt="Some img">`? &name=`image` &int=`1`]]