We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6902
    • 126 Posts
    ??? Can this be done? ...

    The Setup:

    • Website X uses several different templates.
    • Some of these templates are variations of each other, e.g. A1, A2, A3, B1, B2, C1, C2, etc.
    • The resources for the "variants" all reside in the same template folder on the server.

    I would like to have a nice, flexible shorthand for the path to each template folder, that doesn’t break chunks/snippets/etc when a page’s template is changed, or can be utilized across chunks/snippets intelligently.

    I have been using Chunks just to have shortcuts, in linking to files: href="[[++base_url]]assets/templates/myTemplate/somefile" -- becomes --> href="[[$tpl]]somefile" This method saves a lot of typing, but a snippet has to be created for each separate path and used specifically... it’s not really dynamic.

    Several bulbs went off when I saw property sets in action at the ModXpo (plug: everyone should try to go next year! My head is still swimming.) Property sets are, in a word, badass. I digress.

    So, armed with new knowledge, I create templates A, B, C, etc., then add property ’tpl’ to each with the appropriate path for each. Now those paths are accessible in content and chunks ( [[+tpl]] ) and snippets ( $modx->getPlaceholder(’tpl’); ). That works great, and it ensures that the same snippet/chunk called from any page will pull from the correct folder based on the template setting of the page.

    Here’s the twist... If I have templates A1, A2, A3, etc ... they all have the same path, I want to only have to set that variable in one place. I’m thinking this is the perfect place for a property set. So, I create a property set, assign it to all of the templates, and... doh! How do I tell the template to use that property set by default? I could just import the property set to the default set, but then if I have to update the path, that would still mean going back into each template and updating the property or reimporting the updated set.

    I’m sure that this method could be used for something more useful than paths (let your imagination wander). I also suppose I could be going about this the completely wrong way. To me, though, it doesn’t fit in a TV because it’s above the resource level - and it’s above the template level, really, too. It’s below the system level, though, so it doesn’t seem to fit as a system setting. I suppose you could use a snippet to test the template setting somehow... but a property set just seems more elegant...







      • 3749
      • 24,544 Posts
      At present, a custom property set can only be attached to a an element that has a tag (IOW, not templates). I think there may be plans to change this down the road, but I don’t know how the attachment would be specified.
        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
        • 6902
        • 126 Posts
        I guess there would have to be another field in the manager in the template editor (makes the most sense to me for it to be there). "Assign property set:" with a drop-down or the like.
          • 22303 MODX Staff
          • 10,725 Posts
          Couldn’t you just set a system or context setting and make that the value of your common path? You specify it once in settings then use [[++setting_name]] as the value of your Template property? Or is there another reason to do this as a property set other than only having to set the value in one place?
            • 24393
            • 83 Posts
            I am using Jason’s method to create dynamic templates using a context key, e.g. assets/templates/[[++context_key]]/styles.css. However, I had to create a [[++context_key]] setting for each context. Shouldn’t [[++context_key]] return the, err... context key, or am I using the wrong tag?
              stevesunderland.com
              GRAPHICS | INTERACTIVE | MARKETING
              xhtml + ajax + seo websites powered by modx
              • 28215
              • 4,149 Posts
              Try [[*context_key]]
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 14883 ☆ A M B ☆
                • 450 Posts
                I think there may be some overlap between what you are trying to do and the template method I’ve been working on. My templates contain a single chunk call with custom arguments that get passed through to inner chunks. I wrote a blog post about it a while back (http://ichosemodx.wordpress.com/2010/04/12/thoughts-on-developing-a-template-strategy-and-my-new-template-click-through-utility/). I’ve made some changes to my approach since then but that will give you the general idea.

                Anyway, I had the thought of using Property Sets with this approach. When I first tried it it didn’t work because Property Sets didn’t behave the same way as direct arguments. I think OpenGeek was going to change that for the sake of consistency: http://modxcms.com/forums/index.php/topic,48924.msg286141.html#msg286141. Not sure what the current status is.

                Hope this helps in some way.