We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Quote from: legues at Jun 30, 2011, 10:16 AM

    Why don´t you also try getResources plugin? You can push from your custom resources a tv created by you and shown in a specifi template created bty you... well this is just an idea!!!! But i think you have your problem solved!!!!
    http://rtfm.modx.com/display/ADDON/getResources


    completely solved the problem!
      palma non sine pulvere
    • maybe is not bad idea to str_replace quotes something like this:

      $text = str_replace('"', '', $text);


      because when we have "" inside in the <meta... is not valid smiley
      Cheers
        palma non sine pulvere
        • 3749
        • 24,544 Posts
        I think you could use &quot; but I guess that could be automated.

        $text = str_replace('"', '"', $text);
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
        • something in extra...i have strange situation:
          in my document i have for content some getResources call:

          [[!getResourcesTag?  &parents=`1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20` &elementClass=`modSnippet` &element=`getResources` &tagKey=`CLOUDkeywords` &tpl=`mytplseo` &tagRequsetParam=`tag` &toPlaceholder=`results`]]


          for same dodument i have in template header:

          [[DynamicDescription? &maxWordCount=`50`]]


          but i have NO results in <meta name="description" content="" /> , ideas?
          Thanks
            palma non sine pulvere
            • 3749
            • 24,544 Posts
            If the descriptionTv TV is empty, the code uses the resource content, but I think your resource has no content at that that point since the DynaDescription tag is above the getResourcesTag tag. There’s nothing there but the getResourcesTag tag, which is removed.

            I think your only option is to put something in the dectriptionTV TV.

            The only alternative I can think of is to put the DynamicDescription code in a plugin connected to OnWebPagePrerender and have it inject the description into the header with $modx->regClientStartupHTMLBlock().
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
            • Quote from: BobRay at Aug 16, 2011, 11:11 PM

              If the descriptionTv TV is empty, the code uses the resource content, but I think your resource has no content at that that point since the DynaDescription tag is above the getResourcesTag tag. There’s nothing there but the getResourcesTag tag, which is removed.

              I think your only option is to put something in the dectriptionTV TV.




              i make another trick, but is not PURE smiley

              [[If? &subject=`[[DynamicDescription? &maxWordCount=`80`]]` &operator=`EQ` &operand=`` &then=`[[*introtext]]` &else=`[[DynamicDescription? &maxWordCount=`80`]]`]]



              Quote from: BobRay at Aug 16, 2011, 11:11 PM

              The only alternative I can think of is to put the DynamicDescription code in a plugin connected to OnWebPagePrerender and have it inject the description into the header with $modx->regClientStartupHTMLBlock().

              how this is possible?
                palma non sine pulvere
                • 3749
                • 24,544 Posts
                Delete the snippet tag from the template.

                Create a plugin with the following code (untested). On the System Events tab of the plugin, check OnWebPagePrerender.

                On the Default Properties tab of the plugin, create the following properties and set their values appropriately:

                maxWordCount
                useResourceDescription
                descriptionTv


                <?php
                $resource =& $modx->resource;
                
                
                $pid = $resource->get('id');
                
                $mwc = $scriptProperties['maxWordCount'];
                $maxWordCount = (!empty($mwc) && is_numeric($mwc)) ? $mwc : 25;
                
                /**
                 * Function: getdynadescription()
                 * Returns:  A string of text ready to be placed in a meta description tag
                 */
                if (!function_exists(getDynaDescription)) {
                  function getDynaDescription($text='',$excerpt_length=25)
                  {
                    global $modx;
                    $text = str_replace(']]>', ']]>', $text);
                    /* remove line breaks */
                    $text = str_replace("\n",' ',$text);
                    $text = str_replace("\r",' ',$text);
                    /* entify chars */
                    $text = htmlEntities($text);
                    /* remove special MODx tags - chunks, snippets, etc.
                     * If we don't do this they'll end up expanded in the description.
                     */
                    $text = $modx->stripTags($text);
                    $words = preg_split ("/\s+/", $text,$excerpt_length+1);
                    if (count($words) > $excerpt_length) {
                      array_pop($words);
                      array_push($words, '...');
                      $text = implode(' ', $words);
                    }
                    return trim(stripslashes($text));
                  }
                }
                
                $output = '';
                
                if ($scriptProperties['useResourceDescription']) {
                    /* If &useRessourceDescription is set, use that */
                    $output = $modx->resource->get('description');
                
                
                } else if (!empty($descriptionTv)) {
                  /* Try the TV */
                    if (!empty ($scriptProperties['descriptionTv'])) {
                
                        $tv = $modx->getObject('modTemplateVar',array('name'=>$scriptProperties['descriptionTv']));
                        $output = $tv? $tv->getValue($pid) : '';
                    }
                }
                
                if (empty($output)) {
                  /* still empty, use the content field */
                
                    $content = $resource->getContent();
                    $output =  getDynaDescription($content,$maxWordCount);
                }
                
                /* Create the full tag if &fullTag is set */
                if ($fullTag == true) {
                       $output = '<meta name="description" content="' . $output . '">' . "\n";
                }
                
                $modx->regClientStartupHTMLBlock($output);
                
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting