We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26401
    • 247 Posts
    Howdy

    I’m using the same template content for a bunch of my templates, so I’ve put the template inside a chunk and I’m calling inside each template. The reason I do this is because I can give different TVs and manage permissions this way.

    But I find I would like to have a placeholder that I can fill from the template as opposed to the different resources. Is there a way of injecting this without braking apart the template?
      • 16895
      • 87 Posts
      Not an overly neat solution, but if I understand your post correctly then I assume the following will work:

      Template:
      <?php $foo = ’bar’; ?>

      Chunk:
      <?php echo $foo; ?>

      I’m not sure if you can execute PHP inside a template---you could write a snippet which does the same thing.

      UPDATE: Oops, can’t use EVAL.
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Can you reword the question? Maybe it’s that I haven’t had coffee for a week, but I couldn’t follow that. Templates in chunks?
          • 3749
          • 24,544 Posts
          I’m afraid I can’t make any sense out of it either. Templates are the things you see in Elements | Manager Elements | template tab. The template-like things you put in chunks and use for snippets like Ditto and Wayfinder are called Tpl chunks.

          Most sites can get by with just one or two Templates. Neither chunks nor templates have TVs.

          If you explain exactly what you’re trying to do and why, without assuming any particular use of MODx elements, we might be able to suggest a much simpler method.
            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
            • 23510
            • 168 Posts
            Neither chunks nor templates have TVs

            Indeed templates have TVs, not so? Thats what TVs are attached to.
              • 26401
              • 247 Posts
              sorry guys, let me try again


              let’s say...
              I have a chunk called template_chunk that has the template content <body>[*#content*][+footer+]<body>

              and then I have three templates tpl_1, tpl_2, and tpl_3, and each of them have {{template_chunk}} as the content

              Now I want another template tpl_4 to inject something inside the [+footer+]. I want the template to do this, not the resources.



              and the reason...

              aside from that [+footer+] the templates are exactly the same, so if I’m doing updates, I just update the chunk. And I can assign different managermanager rules and TVs.


              I’ve tried running a snippet before the chunk call in the template that would set the placeholder
              [[inject? &placeholder=`footer` &content=`another chunk` ]]
              {{template_chunk}}

              but now as I’m looking at it, I’m thinking I could extend the snippet to deal with the placeholder, and I can give it more control whether the resource or template replaces the placeholder.
                • 3749
                • 24,544 Posts
                Quote from: pixelstation at Mar 18, 2010, 10:28 PM

                Neither chunks nor templates have TVs

                Indeed templates have TVs, not so? Thats what TVs are attached to.

                Right, I should have been clearer. The TVs belong to templates, but they don’t a real value except in relation to a particular resource.
                  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
                  • 3749
                  • 24,544 Posts
                  Quote from: daspoda at Mar 18, 2010, 10:52 PM

                  sorry guys, let me try again


                  let’s say...
                  I have a chunk called template_chunk that has the template content <body>[*#content*][+footer+]<body>

                  and then I have three templates tpl_1, tpl_2, and tpl_3, and each of them have {{template_chunk}} as the content

                  Now I want another template tpl_4 to inject something inside the [+footer+]. I want the template to do this, not the resources.
                  and the reason...

                  aside from that [+footer+] the templates are exactly the same, so if I’m doing updates, I just update the chunk. And I can assign different managermanager rules and TVs.

                  I’ve tried running a snippet before the chunk call in the template that would set the placeholder
                  [[inject? &placeholder=`footer` &content=`another chunk` ]]
                  {{template_chunk}}

                  but now as I’m looking at it, I’m thinking I could extend the snippet to deal with the placeholder, and I can give it more control whether the resource or template replaces the placeholder.

                  If I’m understanding you, it sounds way more complicated than it needs to be. Just put <body>[*#content*]{{footer}}<body> in your Template (not in a chunk) and put the footer content in a chunk called "footer."

                  The footer chunk can use a placeholder, a TV, or a snippet to inject its particular content. In addition, different templates can use a different footer chunk, though many users create more templates than are necessary, which makes their sites harder to maintain.

                  If that won’t work, we need more details about what you’re trying to do. What is it that you want to inject into the footer and why don’t you want it tied to particular resources?

                    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
                    • 26401
                    • 247 Posts
                    ah, yes except it’s a lot more complicated than <body>[*#content*][+footer+]<body>, that was just an example.

                    My concern is when it comes to updating, it’s easy to forget where extra content was added and after a wild cut and paste spree find yourself overwriting something you didn’t intend to. And with modx not doing undo yet (one can hope) it can get hard to get back some of the changes.

                    While I do back up my stuff, something like this could reduce errors.


                    at the moment I do have the modified template in the template as many will argue is intended so it’s not the most important feature, but I am curious if this can be achieved, and why the placeholder injection isn’t working.

                    I guess the setPlaceholder have to be in the same run of php code as a parseChunk for it to work.