We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42393
    • 143 Posts
    I'm really sorry if I've missed basic core functionality here.

    I have a resource 123 which is based on template T1. It has a tv_Foo. Without code, can I get another resource to display the value of that TV? Something like:

    [[^resourcenameOrId:value]]
    or
    [[getValue &resourceID=`123` &value=`*tv_Foo`]]

    The first example was described in a very old thread describes this concept. Was that ever implemented?

    The second example which can be implemented with a snippet. I'm thinking all properties of the resource (id, alias, title) could be accessible by name in &value, or by indirect reference for TVs with the "*" prefix. And to access a specific resource, &resourceAlias=`pagename` would eliminate hardcoding an ID.

    Thanks!
      Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
      • 35150 ☆ A M B ☆
      • 191 Posts
      Quote from: captainstarbuck at Dec 31, 2012, 02:47 PM

      I have a resource 123 which is based on template T1. It has a tv_Foo. Without code, can I get another resource to display the value of that TV?

      There are several extras which do exactly that. Have a look at:

      FastField (http://modx.com/extras/package/fastfield) – A clever idea and works like your first example.

      getResourceField (http://rtfm.modx.com/display/ADDON/getResourceField) – The old standby. Works like your second example.

      ShowTV (http://modx.com/extras/package/showtv2) – a new one just for TVs. I haven't tried it, but it seems to offer just a subset of the others' functionality?

      Then one I submitted to the Extras repository yesterday but which isn't available there yet: setPlaceholders (https://github.com/oo12/setPlaceholders). I wrote it primarily to make setting placeholders easy outside a snippet (effectively it adds local variables to templates and chunks), but it happens to do everything getResourceField can plus some more.
        Extras :: pThumb • Resizer • imageSlim • setPlaceholders
        • 10208 ☆ A M B ☆
        • 1,780 Posts
        You may be interested in this "Ronin" behavior:

        Quote from: opengeek at Nov 08, 2012, 12:23 PM
        Template Variables that are not assigned to a Template will still render the default value in a Resource with that Template. It is a known behavior, referred to affectionately as "Ronin" TVs (see issue #1852) for an older discussion on the subject.
          Frogabog- MODX Websites in Portland Oregon
          "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
          Having server issues? These guys have MODX Hosting perfected - SkyToaster
          • 42393
          • 143 Posts
          @frogabog: I can't see yet how "Ronin" can help resource1 get any value from resource2.

          @jgrant: setPlaceholders looks like what I'm asking for.

          Your example for the output filter shows :setPlaceholders=`fb`, which is the only example where you're setting the name of a saved value. In the prior examples, the reference to the value seems to be hard-coded to the name of the source, as in [[+sph.pagetitle]]. This seems to limit those references, in this case to one pagetitle reference per page. How would you use your first example to access multiple resources. For example:

          [[setPlaceholders? &id=`13`
          &fields=`pagetitle || tv.someTV !! [[snippetX]] || get.person` &placeholders=`color==#blue`]]
          :setPlaceholders=`r13`

          [[setPlaceholders? &id=`14`
          &fields=`pagetitle || tv.someTV !! [[snippetX]] || get.person` &placeholders=`color==#red`]]
          :setPlaceholders=`r14`

          and later: The page [[+sph.r13.pagetitle]] is [[+sph.r13.color]] and [[+sph.r14.pagetitle]] is [[+sph.r14.color]]

          It doesn't look like fastField allows for an alias versus ID - does setPlaceholders? I really don't like the idea of hardcoding IDs. I'm trying to avoid the [[~id]] tag because of this and would prefer to use links with an alias like [[~alias]], or apropos to this thread, something like [[~[[+sp.r31.id]]].

          Thanks!
            Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
            • 3749
            • 24,544 Posts
            I recently released the ShowTv extra to do exactly that: http://modx.com/extras/package/showtv2.

            The docs are here: http://bobsguides.com/showtv-tutorial.html.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 35150 ☆ A M B ☆
              • 191 Posts
              Quote from: captainstarbuck at Dec 31, 2012, 05:33 PM
              In the prior examples, the reference to the value seems to be hard-coded to the name of the source, as in [[+sph.pagetitle]].

              Yeah, it sets the placeholder name to a prefix ('sph.' by default) plus the field name. If you needed to work with the same field from two different resources you could call setPlaceholders twice using a different prefix each call. So say you're working on a template, have a TV named varA and need to use its value from two different resources. You could do something like:

              [[setPlaceholders? &id=`13` &field=`tv.varA` &prefix=`r13.`]]
              [[setPlaceholders? &id=`14` &field=`tv.varA` &prefix=`r14.`]]


              That would give you [[+r13.tv.varA]] and [[+r14.tv.varA]]. That's assuming you'll need those values more than once in a template. If they only occur once, add &output=`1` and don't worry about the placeholder name.


              Quote from: captainstarbuck at Dec 31, 2012, 05:33 PM
              [[setPlaceholders? &id=`13`
              &fields=`pagetitle || tv.someTV !! [[snippetX]] || get.person` &placeholders=`color==#blue`]]
              :setPlaceholders=`r13`

              [[setPlaceholders? id=`14`
              &fields=`pagetitle || tv.someTV !! [[snippetX]] || get.person` &placeholders=`color==#red`]]
              :setPlaceholders=`r14`

              Calling like that–as both a snippet and an output filter–isn't what you want to do. Use &prefix in the snippet call instead to change the placeholder names for the things in &fields. Stuff set via &placeholders you can name whatever you want, so just use a different name for the two colors to keep them separate. Here's a better version, simplified just a bit:

              [[setPlaceholders? &id=`13` &prefix=`r13.`
              &fields=`pagetitle || tv.someTV`
              &placeholders=`color1==#blue || color2 ==#red`
              ]]

              [[setPlaceholders? &id=`14` &prefix=`r14.` &fields=`pagetitle || tv.someTV`]]


              That gives you [[+r13.pagetitle]] [[+r13.tv.someTV]] [[+color1]] [[+r14.pagetitle]] [[+r14.tv.someTV]] and [[+color2]].


              Quote from: captainstarbuck at Dec 31, 2012, 05:33 PM
              It doesn't look like fastField allows for an alias versus ID - does setPlaceholders? I really don't like the idea of hardcoding IDs.

              No, most everything tends to use IDs. They're (comparatively) more permanent. Anybody can edit a resource and change the alias as many times as they like. Also multiple resources can have the same alias. ID's aren't set in stone of course, but you can't change them short of creating a new resource, or messing around in the database. Also a given ID is unique and references exactly one resource. Learn to love the ID then? smiley
                Extras :: pThumb • Resizer • imageSlim • setPlaceholders
                • 10208 ☆ A M B ☆
                • 1,780 Posts
                Quote from: BobRay at Dec 31, 2012, 05:56 PM
                I recently released the ShowTv extra to do exactly that: http://modx.com/extras/package/showtv2.

                The docs are here: http://bobsguides.com/showtv-tutorial.html.

                That's really nice, and such a sensible snippet Bob. Thank you! What would we do without you?

                Quote from: captainstarbuck at Dec 31, 2012, 05:33 PM
                @frogabog: I can't see yet how "Ronin" can help resource1 get any value from resource2.

                It's just interesting, and I'll admit that I didn't read your post really well. But in case you wanted a global TV ever, set it's default and assign to no template, use wherever you like.
                  Frogabog- MODX Websites in Portland Oregon
                  "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                  Having server issues? These guys have MODX Hosting perfected - SkyToaster
                  • 42393
                  • 143 Posts
                  @frogabog - your note did send me off to learn about that interesting feature, so it wasn't a waste.

                  @BobRay - it is looking like showtv is a subset of setPlaceholders. Since I'm just starting, I'm inclined toward the all-in-one option at the moment, unless there's more in there that I can't see?

                  @jgrant - thanks for that clarification. It looks like you've handled everything.

                  <OT soapbox>
                  While I understand what you're saying about IDs versus an Alias, I must strongly disagree. If a new page assumes responsibility for an old one (same alias) every element in the CMS needs to change. That's bad. I never use real or meaningful IDs in an application. Examples include phone numbers, USA Social Security Numbers, Driver's license IDs, First or Last Name, Product ID, etc. Those are fields within a database record and should not be IDs. As soon as someone determines that some ID is going to be carved in stone (and hard-coded into pages), it's going to change. Either the application will need a huge change, or database references will need to be zapped - even in a CMS. A reference like [[~123]] should point to the essence of what we want to say, not the physical location of where it's stored. Since only one resource can be active for any given alias (?) it only seems reasonable that a utility which references [[~alias]] should go to the one and only active resource for that alias, and from there we can derive the ~id.

                  I'll qualify all of that with "this is my experience over the last 30 years though it may not apply to this specific environment, and I'm sure I will get better educated over time here". smiley Unless there is already a snippet for this, I'm inclined to write one that uses an alias to lookup the first available active resource and then retrieve its ID, rather than ever using [[~123]]. I know there are already other snippets that retrieve the ID for different reasons but this one function seems important to me at the moment.
                  </>

                  Thanks all.
                    Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
                    • 3749
                    • 24,544 Posts
                    setPlaceholders is an API call and it's great if you're comfortable with rolling your own Snippets. ShowTv is a Snippet that will display any TV (whether it's connected to the current Template or not), which is handy for folks who aren't comfortable working in PHP.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 10208 ☆ A M B ☆
                      • 1,780 Posts
                      Quote from: captainstarbuck at Dec 31, 2012, 09:40 PM
                      If a new page assumes responsibility for an old one (same alias) every element in the CMS needs to change.

                      This is where the id's shine in MODX. Sure, internal links will have to be modified, but they would in any case. I'm a simple girl, so modifying only requiring the changing id's provides me satisfaction. External links remain automatically directed to the correct resource and my time is reduced considerably. With all the shenanigans going on around me (tadpoles x 3 = CHAOS!), singular thoughts sometimes mean the difference between mistakes and competent productivity heh... (plus it's fast)

                      I think it's more difficult to deal with aliases than id's, especially when your alias is something like "contact-local-distributors" or something equally complex (i.e. more than one word). Being able to call a resource by id anywhere, everywhere within MODX is actually one of the strongest benefits IMO. It's also a nice method for editors, who when presented with something so simple, are able to recall the syntax easily. Or it's as simple as a tiny post-it showing [[~id]].

                      (anyone else notice that MODX tags don't need to be surrounded by code tags in the forum anymore? Who knew?)



                        Frogabog- MODX Websites in Portland Oregon
                        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                        Having server issues? These guys have MODX Hosting perfected - SkyToaster