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

    Here’s my new problem... :-(
    I’ve made some snippets which call $modx->getChunk($chunkName) and everything went very well, so I decided to re-use this, but this time, it seems that it returns nothing (actually, it returns an empty string).

    A little bit more info :

    - The chunk name is passed as a parameter of the snippet and is a simple string "hardcoded" in the template (I mean, this is not the result of any other operation like a placeholder being transformed like in my previous problem)
    - The chunk name is received correctly in the snippet
    - A chunk actually exists with that name and contains some html code
    - I tried to hardcode the chunk name in the snippet code, but the results aren’t much better (in fact, not better at all).

    $attTpl = isset($tpl)?$tpl:NULL;
    if($attTpl == NULL) return "Template is missing" ;
    
    ....
    
    $attChunk = $modx->getChunk($attTpl);
    if(empty($attChunk)) return "Chunk is empty !" ;
    
    ....
    


    I added the empty($attChunk) in order to debug the snippet and it always returns "Chunk is empty !"


    If you have any question about my problem, or any idea to solve it, it is welcome smiley

    Thanks in advance !


      • 5727
      • 160 Posts
      To get a deeper look, try this: (It should give you more clues)

      <?php
      $attChunk = $modx->getChunk($attTpl);
      if(empty($attChunk))
      {
          return "Chunk is empty !\n attChunk = ".var_export($attChunk,true)."\n attTpl= ".var_export($attTpl, true) ;
      }
      ?>


      (Disclaimer: the code above is untested! wink )

        Olivier Deland
        Montreal, Canada - Web Developer
        • 25186
        • 25 Posts
        I gave it a try, and here’s what’s echoed :

        Chunk is empty ! attChunk = NULL attTpl= ’filmCommentaire’

        I double-checked and a chunk named ’filmCommentaire’ actually exists ! (without the quotes of course smiley)

          • 5727
          • 160 Posts
          Quote from: rmic at Jun 04, 2007, 12:25 PM

          I gave it a try, and here’s what’s echoed :

          Chunk is empty ! attChunk = NULL attTpl= ’filmCommentaire’

          I double-checked and a chunk named ’filmCommentaire’ actually exists ! (without the quotes of course smiley)



          The problem is that you used ’ instead of ` when passing your parameter, that’s why your attTpl has the single quotes included, so it is looking for ’filmCommentaires’ instead of filmCommentaires
          Use back ticks, not single quotes. (In your snippet call)
            Olivier Deland
            Montreal, Canada - Web Developer
            • 25186
            • 25 Posts
            I’d wish it could be so easy smiley

            here’s my snippet call :

            [!MovieAttribute? &name=`commentaire` &tpl=`filmCommentaire`!]
            



            Note : for the french speaking people among you, I’ve posted about the same topic on the french community : link.
              • 5727
              • 160 Posts
              Aaah, indeed. Nevermind, I’m clueless sad
                Olivier Deland
                Montreal, Canada - Web Developer
                • 27376
                • 576 Posts
                Try clearing your cache in the manager.

                [tt]getChunk()[/tt] only returns null when the chunk doesn’t exist, so I’d double (maybe even triple) check the configuration. Remember that chunk names are case sensitive.
                  • 25186
                  • 25 Posts
                  What do you mean by "configuration" ?
                  If you are talking about the chunk name, I checked once again, and it actually exists.

                  I’ve been able to see that getChunk() works fine with some "older" chunks but not with ’new’ ones,... maybe it can help ...

                    • 3515
                    • 19 Posts
                    Hi, people! Sorry for enter dialog w/o invitation, but I have the almost same problem:
                    here’s my code (external PHP file):
                    include_once('../manager/includes/config.inc.php');
                    include_once(MODX_MANAGER_PATH.'includes/document.parser.class.inc.php');
                    global $modx;
                    
                    function generate_content($art){
                    	global $modx;
                    	$main_section_tpl=$modx->getChunk('main_section_tpl');
                    }
                    

                    this code - is a part of parser of XML-file, $main_selection_tpl - is a variable, wich have to get a content of the chunk named main_section_tpl (with placeholders) for parsing in future.

                    content of the main_section_tpl is:
                    <table cellspacing="0" cellpadding="0" border="0" id="commons">
                    	<tr>
                    		<td rowspan="2"><a href="[big_image]" target="_blank"><img src="[image]"></a></td>
                    		<td valign="top"><h3>[title]</h3></td>
                    	</tr>
                    	<tr><td>[description]</td></tr>
                    </table>
                    


                    Note, that [big_image],[image],[title] and [description] is NOT MODx placeholders - but placeholders, wich I want to use with PHP-parser, part of wich you can see above. And everytime line
                    "$main_section_tpl=$modx->getChunk('main_section_tpl');"
                    returns NULL...

                    Actually, that’s what I’m planning to do:
                    1. Load data from the XML file via PHP
                    2. Parse this data and create documents tree structure from the data scheme of xml file
                    3. fill documents with data, which will placed inside placeholders of the chunk wich showed above.

                    Any ideas? Thanks in advance!
                      • 3515
                      • 19 Posts
                      I solved a problem (by the very far way):

                      include_once('../manager/includes/config.inc.php');
                      include_once(MODX_MANAGER_PATH.'includes/document.parser.class.inc.php');
                      global $modx;
                      
                      function generate_content($art){
                      global $modx;
                      $res = $modx->db->select("snippet", $modx->getFullTableName('site_htmlsnippets'), "name='main_section_tpl'");
                      $chunk=$modx->db->getValue($res);
                      ...
                      }