We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13037
    • 36 Posts
    Hi,

    I’m afraid I’ve been out of the loop for a bit with ModX.

    I want to add some PHP to my template.

    What is the best way to do this?

    Do I create a ’chunk’ and reference this in the template?


    Thanks for any helpers.
      • 4310
      • 2,310 Posts
      Snippets are the method for executing PHP in a template, they can be called from a chunk if needed.
        • 13037
        • 36 Posts
        Hey bunk,

        That’s brilliant!

        So I have a snippet called ’images’

        I have a chunk called ’bgimages’

        What should my chunk contain? [[images]] ?

        And then when I call it in my template, would it be: {{bgimages}}


        Thanks for your help once more
          • 26363
          • 6 Posts
          can you post here the content of your chunk and snippet?

          and maybe this helps you to understand how chunks and snippets work:http://www.slideshare.net/atmaworks/modx-evo-basic-cheatsheet-1-3
            • 4310
            • 2,310 Posts
            Yes, you can do it just as you’ve shown.
            Equally you can just put the snippet call directly in the template.
              • 13037
              • 36 Posts
              Resolved it smiley

              Snippet - was PHP
              Chunk - was [[snippetname]]
              Template - was {{chunkname}}


              Thanks for your help again
                • 13037
                • 36 Posts
                Quote from: bunk58 at Aug 10, 2010, 08:46 AM

                Equally you can just put the snippet call directly in the template.

                Pray, tell.

                How do I do this?


                Thank you
                  • 4310
                  • 2,310 Posts
                  Just add [[SnippetName]] in the template wherever you want the output to appear.
                  e.g. (see the Wayfinder snippet call in the Main Nav section)
                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns="http://www.w3.org/1999/xhtml">
                  <head>
                  	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
                          <base href="[(site_url)]" />
                  	<link rel="stylesheet" href="assets/templates/default/global.css" type="text/css" media="screen"/>
                  	<link rel="stylesheet" href="assets/templates/default//main.css" type="text/css" media="screen"/>
                  	<link rel="stylesheet" href="assets/templates/default/print.css" type="text/css" media="print"/>
                  	<title>[(site_name)] | [*pagetitle*]</title>
                  	<meta name="description" content=""/>
                  	<meta name="keywords" content=""/>
                  	<meta name="robots" content="index, all, follow"/>
                  	<script type="text/javascript" src="assets/js/jquery-1.3.2.min.js"></script>
                  
                  </head>
                  <body>
                  	<div id="wrapper">
                  			
                  	<!--innerContent Panel -->
                  		<div id="innerContent">
                  		
                  		<!--Strapline & Logo Panel -->
                  <div id="starter"></div>
                  	<div id="header">
                  <img src="assets/images/td-logo.png" alt="My Web Site" width="776" height="75" />
                  	</div>	
                  		<!--Main Nav -->
                  <div id="menu">
                  			[!Wayfinder? &config=`main`!]
                  		</div>	
                  		<!-- Sub Panel -->  
                  		<div id="subPanel">
                  			
                  [*side_panel*]
                  				</div>
                  	
                  			
                  				
                  		<!--Main Content Panel -->	
                  		<div id="mainContent">
                  <h1>[*longtitle*]</h1>
                  			[*content*]
                  			</div>
                  		
                  		<!-- Footer & Credits -->
                  			<div id="footer"><p>© My Web Site 2010<br /> 
                   </div>
                  
                  			</div><!--Close innerContent Panel -->
                  		</div><!--Close Wrapper -->
                  </body>
                  </html>