We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27210
    • 158 Posts
    I have a Resource "A" that displays data using Template "B".

    Template "B" has a Template Variable called "calling-site-name".

    I want the value of that Template Variable to be set by each of the sites that use Resource "A".

    If i use the @FILE binding, by what mechanism does the file get created? The file will change depending on who is the calling site.

    1. I’m an external site called "Site 1"
    2. I call Resource "A" by xref="Resource-A.html"
    3. Somehow (?) i need to set up the value of the Template Variable "calling-site-name"
    4. I need to extend this to allow another site called "Site 2" to do the same thing (call Resource "A" with a DIFFERENT value set for the Template Variable "calling-site-name"

      • 3749
      • 24,544 Posts
      The @FILE binding assumes that the file exists and doesn’t know or care how it was created. I don’t think that’s your solution.

      You could use a snippet that checks $_SERVER[’HTTP_REFERER’] and sets the TV in code, but it might be better to forget the TV and have the snippet set a placeholder instead unless you need the TV for something else.

      Maybe if you explain what you’re actually trying to do and why, there might be a better way.
        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
        • 27210
        • 158 Posts
        Thank you so much for your help - i’ve been struggling for a while with this.

        Here’s my problem:
        I want many sites to be able to reuse a Resource.

        But there are differences in the final output of the resource. For example, each calling site uses a different top banner, footer, google analytics, etc..

        The core content of the page is the same for each calling site.

        I want each site that uses the Resource to set up its own environment (template variables?) ahead of time and then that environment can be applied to the resource (for example, a different header).

        I don’t want to create a different Resource for each of the calling sites or i’ll just be duplicating the Resource for each calling site.

        I’m concerned also about reentrancy of the code if two calling sites should call the Resource at the same time.

        Thanks again,
        • Why not use a plugin to interrupt the normal parsing and replace the content tag in the $modx->documentObject (which at early stages consists of the raw template) with the content pulled from the relevant database’s site_content table for the required resource? MODx won’t know the difference, and will continue processing. Any chunks or snippets in that content would be taken from the local database.
            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
            • 27210
            • 158 Posts
            Hi Susan,

            Could you elaborate on your suggestion?

            Where would the plugin be invoked?
            Do i create a separate MySQL database for each calling site?
            How does the parsing code know which database to use?


            Edited to say - i’m making progress, studied more MODx documentation and PHP today...