We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41367
    • 4 Posts
    Hey all,

    Fairly new to Modx, and I'm trying to get the resource id of a custom TV. I've tried numerous ways with no luck.

    I notice that I can get the id of the tv by doing: {$tv->id} So as such i've tried numerous things:
    {$tv->parent}
    {$tv->parentid}
    {$tv->resourceid}
    {$tv->resource_id}
    {$resource_id}
    {$resourceId}

    and on and on. I couldn't find a list of everything $tv has in it, and, again, being new to modx I don't understand how to execute PHP from inside the .tpl file or I'd just print_r the thing.

    Anyhow, any help is much appreciated.
      • 3749
      • 24,544 Posts
      The ID of the TV is shown in parentheses next to the TV's name in the Elements tree (assuming that the TV shows up in the tree. If not, or if you need to get it dynamically, you could get the ID like this:

      <?php
      $tvObj =  $modx->getObject('modTemplateVar', array('name' => 'MyTv'));
      $tvId = $tvObj->get('id');
      return $tvId;
      


      FYI, PHP code has to go in a snippet for what you were trying to do. So if the code above was in a snippet called 'GetTvId', you could display it by putting this tag in a chunk, resource, or template:

      [[!GetTvId]]


      The snippet tag would be replaced by the return value of the snippet.

      BTW, the term "resource ID" is usually used only to refer to the ID of a Resource, not a TV. For a TV, it's just the ID of the TV.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.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
        • 41367
        • 4 Posts
        Sorry if i wasn't clear.

        I said that I can already get the id of the tv with {$tv->id}. But I AM wanting to get the resource id that is the (parent?) of the tv. That's what I'm having problems with here.

        The syntax i'm using in the tv template is {$tv->id}, I can't figure out how to get the resource id with this same syntax in the tv template.
        • TVs are not connected to resources; they are called Template Variables because they are connected to templates. So unless you have a template for every resource, any given TV will be associated with all resources using the template(s) the TV is assigned to. One TV, many resources.

          The value of a TV for a given resource may or may not be unique. If you want to collect the resource ID for a known unique TV value, or the IDs of all resources containing said value, you would need to start with the TV ID, then query the site_tmplvar_contentvalues table. This table has three relevant fields, tmplvarid, contentid, and value, so you would need to SELECT the contentid WHERE the tmplvarid equals your TV id, AND the value equals (or contains) the value you're looking for.



            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            What is it you want to do with the TV (IOW, why do you want it)? Maybe there's another way to do what you want.

            You can get the value of the the TV for a specific Resource, or you can get all the TVs that a given resource has access to, but as Susan says, a given TV doesn't have a particular resource attached to it -- it's attached to all Resources that use the Template it's attached to.


            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.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
              • 41367
              • 4 Posts
              The custom tv is a file upload. It's inside of a migx form.

              The thing is, I can see the variable resource_id getting sent to connector.php in a post with firebug. It is the resource_id that is calling the tv.

              See, the file that is uploaded goes to a folder that is separated by the resource id it was uploaded from: (IE: /52/, or /53/). Again, in firebug i can see that the post to /migx/connector.php.

              I understand that the tv can be called from numerous resource_ids, but I need to know the current one that called it, so that I can put the uploaded file into the correct folder.

              Hope that makes sense. It's early here though smiley
                • 3749
                • 24,544 Posts
                I don't know offhand how to do that. Someone who knows more about MIGx may be able to help.


                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.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
                  • 41367
                  • 4 Posts
                  Bump, Anyone have any ideas?