We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40359
    • 25 Posts
    Is there some way, with plugin or something similar, when I open some resource with URL variable e.g. http://mydomain.com/resource.html?onlycontent=true, I want it to load only content into HTML, without standard template parts with head, body and other parts...

    This question has been answered by bsehovac. See the first response.

    [ed. note: bsehovac last edited this post 11 years ago.]
    • You would need a plugin. Keep in mind that the content may or may not need to be parsed, if it has snippets or chunks or other MODx tags the raw content won't do you any good. You would also have to consider caching - is the resource normally to be cached or not.

      Are you planning to use this as an AJAX result? If so, you can use JQuery's load() feature; it takes a second argument consisting of the HTML element, specified by an ID attribute, in the return whose content to use.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 40359
        • 25 Posts
        Quote from: sottwell at May 18, 2013, 09:21 AM
        You would need a plugin. Keep in mind that the content may or may not need to be parsed, if it has snippets or chunks or other MODx tags the raw content won't do you any good. You would also have to consider caching - is the resource normally to be cached or not.

        Are you planning to use this as an AJAX result? If so, you can use JQuery's load() feature; it takes a second argument consisting of the HTML element, specified by an ID attribute, in the return whose content to use.

        I plan to use this as an AJAX result, but template has a lot of uncached snippets and tv's, and it is loading very slow, i need a mouse over effect to load only content text, page title and one tv... Any idea how that plugin would look like? smiley
        • This should do the trick. Create a plugin and attach it to the OnLoadWebDocument event:
          <?php
          if(!filter_has_var(INPUT_GET, 'templateid')){
              return true;
          }else{
              if (!filter_input(INPUT_GET, 'templateid', FILTER_VALIDATE_INT)){
                  return true;
              }else{
                  $templateId = $_GET['templateid'];
                  if($templateId) {
                      $modx->resource->cacheable = 0;
                      $modx->resource->template = $templateId;
                  }
                  return true;
              }
          }
          

          Then request the resource like this: http://mydomain.com/resource.html?templateid=# where # is the ID of the template you want to use.

          There's one disadvantage here though. Notice that I set cacheable=0 for this resource call. That is necessary, otherwise the resource will be cached with your alternate template and it will appear that way every time it's requested. That may slow things down a bit, depending on what's in the content. If the content is just text, it should still be plenty fast.
          • discuss.answer
            • 40359
            • 25 Posts
            Quote from: esnyder at May 20, 2013, 03:44 PM
            This should do the trick. Create a plugin and attach it to the OnLoadWebDocument event:
            There's one disadvantage here though. Notice that I set cacheable=0 for this resource call. That is necessary, otherwise the resource will be cached with your alternate template and it will appear that way every time it's requested. That may slow things down a bit, depending on what's in the content. If the content is just text, it should still be plenty fast.

            Thanks for your respond, it gave me idea to make new resource with snippet, which get document by alias:

            http://mydomain.com/linkhover.html?alias=myalias

            $alias = $_GET['alias'];
            $resource = $modx->getObject(modResource, array('alias' => $alias));
            
            $pagetitle = $resource->get('pagetitle');
            $content = $resource->get('content');
            $introtext = $resource->get('introtext');
            
            $output .= '<div id="pagetitle">'. $pagetitle .'</div>';
            $output .= '<div id="introtext">'. $introtext .'</div>';
            $output .= '<div id="content">'. $content .'</div>';
            
            return $output;
            
            • That's a good idea, should be very fast. You could modify it for general use by using getChunk:
              return $modx->getChunk($chunk,$resource->toArray());