On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I create resources with tags (which are template variables).The tag have CSS styling.
    When I do not give a tag to a resource, then I see my empty CSS styling (for example a big red box where normally the tag title would show, but since I did not specify a tag it is just the red box). Now I created below PHX which basically should work like this... If there is NO title tag specified then show nothing (so NO red box).
    I think my below code is correct, but I see nothing front-end. Even when I have tag titles.
    I already tried replacing the * with +, but no success.


    [+phx:if=`[*tag1*]`:ne=``:then=`
                    <div class="tag">
                        <a class="clearfix show" href=
                        "/search?search=[*tag1*]">[*tag1*]</a>
                    </div>`+] [+phx:if=`[*tag2*]`:ne=``:then=`
                    <div class="tag">
                        <a class="clearfix show" href=
                        "/search?search=[*tag2*]">[*tag2*]</a>
                    </div>`+] [+phx:if=`[*tag3*]`:ne=``:then=`
                    <div class="tag">
                        <a class="clearfix show" href=
                        "/search?search=[*tag3*]">[*tag3*]</a>
                    </div>`+]

    This question has been answered by iusemodx. See the first response.

    • I haven't used PHX since "IF" was released, but the following is taken from the PHX RTFM

      My first code was wrong - but looking at your code, it should work, but give the following a try - its slightly different to yours - it says if the element is empty do nothing, otherwise do something
      [+phx:if=`[*tag1*]`:is=``:then=``:else=`<div class="tag"><a class="clearfix show" href="/search?search=[*tag1*]">[*tag1*]</a></div>`+]


      [ed. note: iusemodx last edited this post 5 years, 2 months ago.]
      • discuss.answer
        If you take a look at the IF snippet, you can see an example here that is pretty much the same as what you are trying to accomplish

        Using IF:
        [[if? &is=`[*tag1*]:not_empty` &then=`<div class="tag"><a class="clearfix show" href="/search?search=[*tag1*]">[*tag1*]</a></div>`]]
        [ed. note: iusemodx last edited this post 5 years, 2 months ago.]
        • Forgot to post:

          If you are using PHX with Ditto you may experience some wierd results, they don't work well together

          If you are using "IF" with ditto, you have to replace "*" with "+" in the "IF" call
          • @iusemodx

            Your reply#3 code worked.

            Still dont understand why my original code and your reply#2 code didnt work (I dont use Ditto together with it), but thank you for your research and help! Problem solved... smiley