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

    I am having a little problem with a nested snippet call on my Modx site. I have a snippet that checks if the site is been access though Facebook or not.

    <?php
    $output = '';
    
    if($_SERVER['HTTP_HOST']=='apps.howirritating.com') {
     $output = $if;
    } else {
     $output = $else;
    }
    
    return $output;
    ?>


    Which works fine unless the ’if’ or ’else’ variable contain a snippet call with parameters. I seems to treat the first back tick in the snippet call as the end of the variable.

    This is my call or one of the problem, this calls a different form depending on where it is requested from. (if_facebook)

    [[if_facebook? &if=`Call Facebook Form`&else=`[!eForm? &formid=`AddForm` &subject=`New Addition` &to=`[email protected]` &tpl=`AddForm` &report=`AddFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`AddStyles`  &vericode=`1` &gotoid=`46`  !]`]]


    This will output "Call Facebook Form" when accessed from Facebook but only outputs "[!eForm? " when accessed normally.

    Is there away the back ticks can be escaped or does anyone know of a way I could work around this problem?

    Thanks in advance
    Ian
      • 29181
      • 480 Posts
      I don’t think you can do it like that.

      <?php
      
      if($_SERVER['HTTP_HOST']=='apps.howirritating.com') {
       echo "Call Facebook Form";
      } else {
      $modx->runSnippet(
              "eForm",
              array(
                  "formid" => "AddForm",
                  "subject" => "New addition",
                  "more" => "parameters"
              )
      )
      }
      
      ?>


      would probably work.

      I may be wrong though.

      Taff

        Adrian Lawley: www.adrianlawley.com
        • 7231
        • 4,205 Posts
        Before you try that check for the alternating snippet call cache settings for embedded snippets [! [[ ]] !] If that does not work than use a "wrapper snippet" to execute the eForm snippet as Taff suggested.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 13077
          • 15 Posts
          Magic.... thanks for the pointer .... I added a new snippet and it will now output 2 different forms depending on where it’s run from .... here it is .... only subtle differences from what you wrote:

          <?php
          if($_SERVER['HTTP_HOST']=='apps.howirritating.com') {
          
          $output = "Call Facebook Form";
          
          } else {
          
          $output = $modx->runSnippet(
                  "eForm",
                  array(
                      "formid" => "AddForm",
                      "subject" => "New addition",
                      "to" => "[email protected]", 
          	    "tpl" => "AddForm", 
          	    "report" => "AddFormReport", 
          	    "invalidClass" => "invalidValue", 
          	    "requiredClass" => "requiredValue", 
          	    "cssStyle" => "AddStyles",  
          	    "vericode" => "1", 
          	    "gotoid" => "46"
                      )
                  );
          }
          
          return $output;
          ?>



          Thanks again.

          Ian