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

    I create a snippet that go to Data base and depending of SQL result returns some HTML
    if result is null return some error message otherwise I need to return HTML Form

    all html code for form I put in chunk
    So how to return chunk from snippet

    if(something)
    return "error";
    else
    return {{MYChunk}}; -- this dont work!!

    help

      • 21257 MODX Staff
      • 730 Posts
      Ipastor, I’m just confused about one thing.
      The HTML that you want to return from the snippet, does that come from a MODx chunk, or are you reading it from your database call in the snippet?
      If you want to return the contents of a MODx chunk, it’s like this
      <?php
      
      //...
      return $modx->getChunk('chunkName');
      
      


      Otherwise, if you have just constructed your html somehow by reading from the database, you can just return the html like..
      <?php
      
      //...
      $html = "<p>pretend I'm some html</p>";
      
      return $html;
      
      


        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 17554
        • 41 Posts
        this is my snippet...
        <?php


        $ttmpFciNum = $_REQUEST["fcinumber"];
        $ttmpFciNum = isset($ttmpFciNum ) ? $ttmpFciNum : ’-1’;

        $myClass = new MyClass();

        $isIn = $myClass ->newFCINumber($ttmpFciNum) ;--- here I check something into DataBAse

        if( $ttmpFciNum == -1)
        return $myCheckFormTmp; --- here is simply form with one input box
        else
        {
        if ($isIn)
        {
        $url = $modx->makeURL(42);
        $modx->sendRedirect($url,0,’REDIRECT_REFRESH’);
        }
        else
        return $modx->getChunk(’MailForm’); ---( here I whant to call [!eForm? &language=`serbian`&formid=`feedbackForm`&to=`[email protected]`&tpl=`eFeedBackFormSRP`&thankyou=`eFeedBackThanksSRP`&report=`eFeedbackReport`&vericode=`0`&mailselector=`department`!])
        so this code I put in Chunk {{MailForm}} ...BUT DONT WORK
        I get page with ’[!eForm? &language=`serbian`&formid=`feedbackForm`&to=`xxx@com`&tpl=`eFeedBackFormSRP`&thankyou=`eFeedBackThanksSRP`&report=`eFeedbackReport`&vericode=`0`&mailselector=`department`!]’
        instead of form



        }
        ?>


        can you help me ?!?
          • 22303 MODX Staff
          • 10,725 Posts
          What you want to do is execute the snippet call directly, and return that output, rather than delegating to a non-cacheable snippet call that will be delayed until the end of the parsing process. See the function $modx->runSnippet().