We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5689
    • 289 Posts
    This isn’t really a feature request, but I want to generate some discussion on this. If there have already been topics relating to this, feel free to link to them here. smiley

    As I learn MODx and try out Revolution, I’m wondering if it’s really necessary to have Chunks and Snippets be separate types of elements. As I work out my templates, I keep having to ask myself whether I should use a snippet or a chunk for my header, footer, etc. I understand that a Chunk can contain no "logic", but a Snippet can. However, is it really necessary to have Chunks in the first place? To me, they just seem like crippled Snippets, if you know what I mean. I don’t claim to know a whole lot about MODx yet, so I may be overlooking something here such as performance issues, etc, but I propose just merging Chunks and Snippets into one type of element. If you want to use this new element without any logic, then simply don’t use PHP tags and it will be treated like a Chunk currently is. My idea sort of follows the idea of a PHP file. A PHP file doesn’t have to contain any PHP if you just want to output some static content, but if you want to use PHP (which obviously makes more sense if it’s a PHP file, but I’m just saying), then you use tags where you have PHP.

    Please tell me what you guys think. laugh

    EDIT: By the way, the reason I might use a Snippet instead of a Chunk for, say, the footer, is because I use PHP to do things like get the current year for my copyright notice.
      I'm learning more about MODx all the time and loving it.
      • 21257 MODX Staff
      • 730 Posts
      Interesting. There are lots of ways to think about these things. Another line of thought has Templates and Chunks merging instead, because they are also very similar.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 5689
        • 289 Posts
        That’s an interesting thought as well. We almost need some sort of sub-templates.

        I’ve been converting a basic HTML layout to templates, chunks, etc for a site I’m working on, and this is what is happening.

        I want to repeat as little code as possible, but I also want to make things easy to manage. I make a chunk for my header and menus. I make a snippet for my footer since I have PHP in it. Within the main part of the page, I have a right and a left div, so I make a chunk/snippet for each. I will use this exact layout for the entire site, and all that changes is the content of the left and right divs.

        Here’s an example of my code that every page needs. For right now, I just left the right div as a chunk. The main content goes in my left div, where I have placed a comment.

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
        	<head>
        		<title>Title</title>
        
        		<meta http-equiv="Content-Language" content="en-us" />
        		<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
        
        
        		<!--[if IE]>			
        			<style type="text/css">
        				.clear {
        					display: inline-block;
        				}
        				.clear {
        					zoom: 1;
        					display: block;
        				}
        			</style>
        		<![endif]-->
        
        		<!--[if lt IE 7]>
        			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        			<link href="styleIE6.css" rel="stylesheet" type="text/css" />
        		<![endif]-->
        
        		<!--[if lt IE 8]>
        			<script src="IE8.js" type="text/javascript"></script>
        		<![endif]-->
        
        		<!--<script type="text/javascript" src="jquery.js"></script>-->
        	</head>
        	<body>
        		{{Header}}
        		{{Navigation}}
        		<div id="canvas">
        			{{Subnavigation}}
        			<div id="main" class="clear">
        				<div id="left">
        					<div id="content">
        						//***** Content of every page goes here
        					</div>
        				</div>
        				{{Right}}
        			</div>
        			{{Summary}}
        		</div>
        		[[Footer]]
        	</body>
        </html>
        


        Even though the important parts of the code are stored in chunks so I can easily change them on all pages, I still have quite a bit of markup that I would need to put on every page. So then I make a chunk called Start and a chunk called End that contain the markup before the comment and the content after the comment respectively. Then all I need for each template is this:

        {{Start}}
        //template specific code here
        {{End}}
        


        However, I think in a very systematic way, and I like my code to be nested in different levels in a way that makes sense, so I don’t like having "all code before the changing content" as a chunk, then the content specific to the template, and then "all code after the changing content".

        I guess what I’m thinking is this. It’d be really nice if I could specify an overall template that included my XHTML DOCTYPE, HTML head info, etc. This overall template would contented a nested reference to a subtemplate that covers everything inside the body tags. This body subtemplate would include a nested reference to a content specific template that would change based on the type of document being used, as specified by the user upon creating the document. Does this make sense?

        Right now, we are limited to one level of templates that the user chooses. I’d like to see a way to nest templates, so to speak, and let the user choose the child template. Right now, it’s like the user chooses the "parent" template, and the template itself is forced to sort out all of the details. I’d like it where the child template called for a specific "parent" template to be loaded. If anybody has any experience with ASP.NET (it’s been a long time for me, too tongue), I believe it worked the same way. This way, it would be very easy to change the entire layout of the page (if desired) for different types of documents (based on user choice with the template option), but every template wouldn’t have to include all the HTML for the page or use chunks to do the same.

        I’m not sure if that made sense, but it’s just an idea. laugh
          I&#39;m learning more about MODx all the time and loving it.
          • 20413
          • 2,877 Posts
          It’s nice with chunks for site administrators. Because they are simple html and can be used with rich text editors.
          It’s always better having too many options than too few.
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • 28215
            • 4,149 Posts
            Quote from: Compeek at Jun 03, 2009, 02:44 PM

            However, is it really necessary to have Chunks in the first place? To me, they just seem like crippled Snippets, if you know what I mean.
            They are useful in a variety of contexts - including being able to allow 3PCs (3rd Party Components) to be able to pass in Chunks to dynamically style their outputs.

            They are also, as has been said here, better with RTEs and non-programmer users.


            I don’t claim to know a whole lot about MODx yet, so I may be overlooking something here such as performance issues, etc, but I propose just merging Chunks and Snippets into one type of element. If you want to use this new element without any logic, then simply don’t use PHP tags and it will be treated like a Chunk currently is. My idea sort of follows the idea of a PHP file. A PHP file doesn’t have to contain any PHP if you just want to output some static content, but if you want to use PHP (which obviously makes more sense if it’s a PHP file, but I’m just saying), then you use tags where you have PHP.

            We’re not going to merge snippets and chunks at this time; doing so would put a huge damper on caching and performance (you’d have to eval/output-buffer the content just to load it properly) and would create a too many unclear lines as to which would be useful.

            Revolution allows complete nesting of Snippets and Chunks - you could easily write a Chunk that has a Snippet in it that gets your copyright year. You might also want to look into Property Sets.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 5689
              • 289 Posts
              We’re not going to merge snippets and chunks at this time; doing so would put a huge damper on caching and performance (you’d have to eval/output-buffer the content just to load it properly) and would create a too many unclear lines as to which would be useful.
              Yeah, I figured processing a chunk is faster than a snippet, so it might not be a good idea to just merge them. Like I said before, you guys know what works; I’m just sort of thinking out loud. smiley

              Thanks for the suggestions. I was reading about PropertySets yesterday, so I’ll look into those again. And yeah, I knew that I could nest snippets and chunks, but it just seemed kind of silly to make a whole snippet for one line of PHP just so I could use a chunk to include it in my template. It’s easier to just make a snippet that handles the whole footer.
                I&#39;m learning more about MODx all the time and loving it.
                • 28215
                • 4,149 Posts
                Quote from: Compeek at Jun 03, 2009, 03:45 PM

                Thanks for the suggestions. I was reading about PropertySets yesterday, so I’ll look into those again. And yeah, I knew that I could nest snippets and chunks, but it just seemed kind of silly to make a whole snippet for one line of PHP just so I could use a chunk to include it in my template. It’s easier to just make a snippet that handles the whole footer.

                Thanks for thinking out loud. We’re completely open to new ideas; but we hope no one gets offended if we shoot them down. wink

                As an example of Property Sets on Elements other than Snippets - the Download page for modxcms.com is not run on a Snippet - just a Chunk with a different Property Set for each release attached to it. The chunk has some default values such as [[+releaseZipId]] (that point to Static Resources via [[~[[+releaseZipId]]]]) and [[+releaseDescription]], [[+releaseDate]], [[+releaseTitle]], etc, whose values are loaded from the specific Property Set. For example, the 0.9.6.3 Chunk call looks like:



                whereas MODx Revolution 2.0.0-beta-1 looks like:



                All that changes are the values of the properties in the respective property sets.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 5689
                  • 289 Posts
                  We’re completely open to new ideas; but we hope no one gets offended if we shoot them down.
                  Hey, no problem. I haven’t spent hours upon hours of time developing this, so I expect those who have to reserve the right to shoot some ideas down. wink

                  That’s interesting with the Property Sets. I’ll have to look into that for sure. I’m not quite sure I completely understand how it works just yet, but I get the general idea. It’s just a matter of inheritance and priority of properties on an element, right? So the chunk for each download think either has a present Release value or none at all, at you’re setting the value for that instance of the chunk to provide link, right? Interesting.
                    I&#39;m learning more about MODx all the time and loving it.
                    • 28215
                    • 4,149 Posts
                    Quote from: Compeek at Jun 03, 2009, 03:57 PM

                    I’m not quite sure I completely understand how it works just yet, but I get the general idea.

                    We’re not either. We think we’ve created a feature that people are going to find uses beyond what we thought possible for. We find new uses for Property Sets weekly.
                      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                      • 3749
                      • 24,544 Posts
                      One of the beauties of property sets is that they allow users to edit snippet parameters in a grid. All the parameters are there with descriptions of what they do so you don’t have to look them up anywhere. You also don’t have to teach users about the syntax of snippet calls -- no worries about back-ticks, missing ampersands, or blowing up your whole snippet with a malformed call. smiley
                        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