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

    I’m trying to do something that I thought would be dead simple: Create a bunch of static resources in a Container and then create a list that does ’something’ with them.

    Well, that ’something’ requires me to use the path to the static resources, something like use getReources to loop through my container using the following &tpl:

    <div class="song-name"><a href="[[+STATICRESOURCEPATH]]" title="[[*pagetitle]] - [[+pagetitle]]" rel="lightbox[audio 50% 20]">[[+pagetitle]]</a></div>


    I can’t seem to find anywhere in the revo documentation any reference to the paceholder that holds that path for a static resource, i.e. the entry in the "Static Resource" field in the manager backend.

    Does anyone know how to do this??
      • 22303 MODX Staff
      • 10,725 Posts
      You NEVER point directly to the source of a static Resource, as that would bypass MODx and all security on the request.

      You generate links to Static Resources exactly the same way you do to any Resource in MODx, using
      [[~[[+id]]]]
      in getResources tpl’s for example.
        • 17304 ☆ A M B ☆
        • 13 Posts
        First of all, thanks for the reply smiley

        Your answer leads me to understand that if what I want generated is a link to the actual URL of, a soundfile let’s say, I’d have to create a file TV and use that in the tpl:
        <div class="song-name"><a href="[[+tv.songFile]]" title="Song sample: [[*pagetitle]] - [[+pagetitle]]" rel="lightbox[audio 50% 20]">[[+pagetitle]]</a></div>

        It works for me, but it feels a little redundant
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          The idea with creating a resource as a "wrapper" around a file is that when you create a MODx static resource, you can assign it permissions and control access to the file. But as far as generating a menu that lists all available resources, it’s handled the same way you would list links to pages. You can write your own Snippet, make use of existing ones (e.g. WayFinder).

          If you are creating a page that also has a related file and you don’t care if people download the file directly, then yes, you could create a page with a TV as you described. Your template sample is mixing placeholder types. Probably you could simply use something like [[*my_mp3]] placed into your template (e.g. into an anchor tag)
            • 12241
            • 80 Posts
            Wait, so if I want to use static resources for images so that I can display them with getResources I have to add the image twice (once in the "Static Resource:" field and then add the image to a custom TV) just so that I can grab the path to the image for use in the "src" attribute??? Shouldn’t I be able to decide how I want to use my static resources? I mean, what kind of security risk (I’m no expert) is posed by just grabbing the file path of a static resource, if the resource is an image for example?

            Maybe I’m missing something, is there an easy way to upload images and then display them with getResources or Ditto or whatever?

            Update
            Duh, the [[+content]] placeholder works for the Static Resource file path. Why didn’t anyone say that since that was the original question??? I understand security but isn’t modx about options and if an option poses no security risk why is it still with held??? Oh well. I guess it was just a dumb question haha
              Environment:
              modx: rev 2.0.8-pl
              localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              Sounds like you’re missing something... how are you adding the image to the TV? If you’re just uploading it as an image, then there’s no need to treat it as a static resource (unless you need anything listed below). You could add a TV that points to the resource and simply returns its id... that’s probably more useful to you.

              When you create a static resource, then you can point to its url just like any other MODx page, using the [[~123]] notation in your templates (where 123 is the page id).

              Just to review the reasons for why you might want to do this... when you add something as a static resource, it allows you to:
              1. to search for it
              2. display it in menus
              3 restrict access to it by associating permissions with the static resource

              But, it also requires more resources because MODx has to stream the resource through PHP.

                • 17304 ☆ A M B ☆
                • 13 Posts
                Hmmm...

                One very common, recurring theme for me, and I guess amongst a number of other newbies is that of attaching images to a resource.

                I guess I could create TV’s for a possible, e.g. 12 images (and captions) and then fill them up as I go (and pray that they end up being <12).

                Or, which is what I tried to do, create a static resource for each and every one of those images, with the parent resource as container, and then do as I will with them when I need to (listing, gallery, etc.). The big advantage of this is that I can "attach" as many as I want as I go along, and handle everything through a nice getResources snippet.

                But looping through static resources with such a snippet and displaying, for a example, a link for each and every one of those attached (static resource) images, kept giving me an error.

                So i ended up creating plain old resources to which I "gave" an image TV, and did everything through there. But somehow this felt like an overkill, because all the other fields I have no use for - all I need is the path to the file, a title and a description.

                I’m thinking that there must be an easy way to attach a bunch of images to a resource - that’s why I asked this question here, in case I’m not getting something.Maybe I’m going about it the wrong way, for MODx (I did start out with ZOPE, a long time ago).
                  • 24732 ☆ A M B ☆
                  • 300 Posts
                  you need Ditto. The example I am going to give you is from Evo but you can change the tags to Revo and use this idea.



                  you place a ditto call in the parent document. Then you make a chunk and put your code snippet in it. Make a custom template with your code chunk in it and assign your tv’s to it. For instance... photo and caption:

                  tvs are : [*myPicTV*] and [*myCaption*]

                  <div class="myRepeatedContent">
                  <img src="mypic.jpg" alt="This is my pic" width="100" rel="slide" />
                  <p class="caption"> This is my lovely caption</p>
                  </div>

                  becomes

                  <div class="myRepeatedContent">
                  <img src="[+myPicTV+]" alt="This is my pic" width="100" rel="slide" />
                  <p class="caption">[+myCaption+]</p>
                  </div>


                  and that is your chunk...name it slide or whatever. Then make a template and in the template you’ll just put:
                  {{slide}}


                  The parent resource has a different template. It would have the template of the entire document. but in the place where the content needs to load then you have a ditto call like this :

                  [!Ditto? &parents=`1` &tpl=`slides` &display=`3` &paginate=`0` !]

                  and then your site tree will look like the attached image, under home we have slides that feed the slideshow on the home page. They edit the resource under it ...we tell them to duplicate an exisiting slide and type over the data but as long as the "slide" template is there, it works. They could create a resource and apply the slide template instead.

                  This was probably the biggest issue I had when I started using modx... understanding the power of ditto. If you grasp this then it will change your life. no kidding. you can take the same idea and use it everywhere.





                  I -think- this is what you are looking for? but anyhow... if not then ignore. and good luck.
                    ________

                    Anne
                    Toad-in-Chief
                    Red Toad Media - Web Design, Louisville KY
                    Hear me tweet: http://www.twitter.com/redtoadmedia
                    "Bring on the imperialistic condiments." - Rory Gilmore