We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44933
    • 17 Posts
    I had a jquery variable " var str=1; "
    I have to use this variable "str" instead of `[[*id]]` in the below code.

    [[!getResources? &parents=`[[*id]]` &tpl=`tpl.menuslide` &includeTVs=`1` &processTVs=`1` &limit=`100` &includeContent=`1]]

    when i replaced it like

    [[!getResources? &parents=`str` &tpl=`tpl.menuslide` &includeTVs=`1` &processTVs=`1` &limit=`100` &includeContent=`1]]

    it doesn't worked. Please give me a solution. Thanks in advance

    Simon
    www.toggletime.net
      Thanks in advance

      Media System Team
      http://www.toggletime.net
      • 16551 ☆ A M B ☆
      • 54 Posts
      This is not possible this way. Snippets are Php (which is done server side) and jQuery is Javascript (which is done client side). This means that the page is already fully parsed and rendered and send to the browser. And then the browser starts to process your Javascript.
        • 44933
        • 17 Posts
        Thanks for your reply.
        Then how can i get the content of child resource and display it in a div, when mouse enter on a div.
          Thanks in advance

          Media System Team
          http://www.toggletime.net
          • 16551 ☆ A M B ☆
          • 54 Posts
          Here are 2 approaches:

          1.
          Put the content in your div and hide it with CSS. Display the div with Javascript on mouseenter (or with CSS on :hover).

          2.
          Create an Ajax request that dynamically loads the content into your div.
            • 44933
            • 17 Posts
            Can you show me how i can create Ajax that dynamically take the content of resource when we pass the parent resource id.?
              Thanks in advance

              Media System Team
              http://www.toggletime.net
              • 16551 ☆ A M B ☆
              • 54 Posts
              This is nothing trivial, but hopefully this gives you a basic idea: http://www.williamastrom.se/blog/jquery-ajax-post-to-get-modx-field-content/

              You want to pass the Id of the desired parent resource to a custom snippet.

              In your snippet you do your getResources call like this
              $output = $modx->runSnippet('getResources', array(
              'parents' => $_POST['yourVariableNameYouPassed'],
              'tpl' => 'tpl.menuslide',
              'includeTVs' => '1',
              'processTVs' => '1',
              'limit' => '100',
              'includeContent' => '1'
              ));
              
              return $output;

              This is untested. [ed. note: labr1005 last edited this post 13 years, 1 month ago.]
                • 44933
                • 17 Posts
                can you also show me how could i call this snippet by passing the variable in jquery.
                  Thanks in advance

                  Media System Team
                  http://www.toggletime.net
                  • 16551 ☆ A M B ☆
                  • 54 Posts
                  I had a jquery variable " var str=1; "

                  Javascript:
                  var str = 1;
                  
                  $.post('ajax', {
                  	parentIds: str
                  }, function(data) {
                  	$('#yourDiv').html(data);
                  });

                  In your resource "ajax" all you do is call a snippet - let's name this "ajaxGetResources".
                  [[!ajaxGetResources]]

                  Snippet "ajaxGetResources":
                  $output = $modx->runSnippet('getResources', array(
                  	'parents' => $_POST['parentIds'],
                  	'tpl' => 'tpl.menuslide',
                  	'includeTVs' => '1',
                  	'processTVs' => '1',
                  	'limit' => '100',
                  	'includeContent' => '1'
                  ));
                   
                  return $output;


                  Still untested.
                    • 44933
                    • 17 Posts
                    what type of resourse is "ajax"?

                    Is "ajax" is a chunk or a resource page?
                      Thanks in advance

                      Media System Team
                      http://www.toggletime.net
                      • 16551 ☆ A M B ☆
                      • 54 Posts
                      "ajax" is a resource page. You can give it an empty template. The snippet "ajaxGetResources" goes into the content of this resource.