We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17786
    • 9 Posts
    Hi, I’m not sure whether this is a bug or not.

    I’ve got a site that uses nested templates -- namely, a master resource (let’s call it ID=1), and several sub-resources that are used to populate sidebars, etc. on the page. As an example, let’s say the sub-resource’s ID=99.

    I am trying to use the [[*id]] resource tag in the sub-resource (ID=99) in connection with getResourceField to refer to a template variable that appears in the sub-resource.

    If I put an [[*id]] statement within the sub-resource, however, because it’s being rendered as a part of the master resource (ID=1), the [[*id]] statement is returning 1, not 99.

    So, when this statement appears in the sub-document:

    [[*id]]

    the ID returned is the ID of the resource of the master page, not the resource in which the statement appears (the sub-document)

    Is this a bug? Isn’t the [[*id]] statement supposed to refer to the actual resource on which the [[*id]] statement is contained, NOT a parent resource or a master resource within which the sub-resource is being rendered?

    Alternatively...if this is the correct behavior...how would I go about referencing the resource ID of the sub-document?

    Thanks for any assistance!
    M2
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It is supposed to refer to the ID of the resource currently being parsed. This is the "master" resource, since the others are being fetched and embedded into it. As to getting the ID of the sub-resource, that would depend on how you are loading the sub-resource.
        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
        • 17786
        • 9 Posts
        Thanks for the reply Susan. Makes sense, and it seems consistent about it, but it wasn’t something I saw documented anywhere.

        So, to your comment -- how am I loading the sub-resources...

        In my case, the sub-resources are being loaded into the master using getResourceField (I had a similar setup in Evo with GetField). The template for the master page contains a series of div’s where the sidebars go, and there’s a template variable in the master where I can specify the resource ID of a sub-resource to populate the <div> for the sidebar.

        This is not necessarily a "child" resource, but just some resource that is based on a minimal template that contains no <head>, no <html> statements, etc. but just the contents of the <div> the sub-resource is designed to populate.

        But since the CSS associated with the sidebar changes depending on which sub-resource is present on the page, I’m trying to use getResourceField in connection with a snippet that calls $modx->regClientCSS to write the required CSS into the head depending on which sub-resource is active. But to do that, I need to get the ID of the sub-resource, not the master. Any suggestions?

        Thanks for the help -- much appreciated.
        M2
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Well, I don’t use Revo, but does the getResource function use placeholders? In that case if you want the ID of the sub-resource, use [[+id]]. Hopefully somebody who knows how Revo and getResource works will set things straight.
            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