We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22897 ☆ A M B ☆
    • 209 Posts
    Hi,

    I have an Image TV, and have written a snippet so that if an image has not been selected, no <img> tag is output.

    That works fine, but I want to pass in attributes for the image tag. I try the following:
    [[ImageIfExists?img=`[+ManagementPhoto+]`&attr=`style="float:left;"`]]

    And the contents of [tt]$attr[/tt] is truncated when it arrives at my program to [tt]styl[/tt]

    How can I work round this? I’m guessing there’s a built-in way in MODx I’ve not found (I’m surprised there’s no way to render an image tag like this built-in, given the image type template variables - is it really not there?).
      MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
      • 10487 MODX Staff
      • 1,535 Posts
      Hi pbowyer,

      The problem with the snippet parameter truncation is that the equals sign is used as a delimiter for snippets when the parameters are being parsed. To get around it, you’ll need to use something in place of the equals sign, eg |eq| and then substitute the equals sign back in within your snippet.

      But, to answer your last question - have you tried the Image widget for that particular TV? It should do what you’re trying to achieve - and IIRC, it shouldn’t output an empty img tag either.

      Let us know how you get on,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 22897 ☆ A M B ☆
        • 209 Posts
        Quote from: garryn at Apr 23, 2007, 12:37 PM
        But, to answer your last question - have you tried the Image widget for that particular TV? It should do what you’re trying to achieve - and IIRC, it shouldn’t output an empty img tag either.
        I haven’t - I can’t find it (or documentation for the image widget) anywhere!

        Is it written about?

        Thanks,
        Peter
          MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
          • 10487 MODX Staff
          • 1,535 Posts
          Documentation is a bit thin on the ground when it comes to widgets. Best bet is to try it out ... just think of widgets as a way of applying some form of styling to the output of a template variable.

          To use the image widget:

          1. Go to your TV definition (Manager->Manage Resources-> Template Variables tab and then select your TV name)
          2. Under the TV properties, you should see an option labelled ’Widget’ - select ’Image’ from that dropdown.
          3. You should now see some widget properties appear below that option for all manner of things like Class, Style, Alternative Text etc.
          4. Enter your desired values and save the TV.

          Now, when you use the widget in your templates (using [*myTV*] syntax), you should see that it gets formatted as an image tag.

          Hope that helps,
          Garry
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 10449
            • 956 Posts
            well, instead of:
            [[ImageIfExists?img=`[+ManagementPhoto+]`&attr=`style="float:left;"`]]

            you could put the style= part into the snippet, not the snippet-call. So:
            [[ImageIfExists?img=`[+ManagementPhoto+]`&attr=`float:left;border: 1px solid black;`]]
            etc. should work fine.

            I’ve used similar stuff for a little random-image snippet recently, and it works fine.
            Same goes for (optional) link, link target, alt- and title-attributes.
              • 6726
              • 7,075 Posts
              You could also use PHx for this, I have done it for a website recently, for which an image widget couldn’t be used since I have installed the DirectResize plugin which needs the image to have a height and width used for automatic redimensionning (DirectResize uses the height and width attributes to caculate the redimensionning, then strips the attributes and replace with the redimensionned height and width. If no image then it does not strip the values and I end up with an empty gap, since the image is floated).

              The only thing is to define a default value for your image TV (in my case, "blank")

              [+phx:if=`[*photo*]`:isnot=`blank`:then=`<img src="[*photo*]" height="180" width="250" style="margin: 0px 0px 10px 15px; border: 5px solid black; float: right;" />`:else=` `+]
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id