We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37123
    • 186 Posts
    Sorry, I'm learning to use MODx Revo and I have a problem (although English is a problem).
    I have to print the alias for the parent resource. I get the id of the parent but not the alias. Who writes me a piece of code to put in the snippet? Thanks to all
      • 3749
      • 24,544 Posts
      Me. smiley

      Put this where you want to show the alias:
      [[!GetParentAlias]]


      And this in the snippet:
      <?php
      /*GetParentAlias snippet */
      
      $parent = $modx->resource->getOne('Parent');
      if (!$parent) {
         return 'No Parent';
      } else {
          $alias = $parent->get('alias')
          if (!empty($alias) {
              return $alias;
          } else {
             return 'Parent has no alias';
          }
      }
      
      [ed. note: BobRay last edited this post 14 years, 11 months ago.]
        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
        • 37123
        • 186 Posts
        thanks but not working. I created the snippet called GetParentAlias ​​with the code that I've posted, then I called the snippet in the template with
        [[! GetParentAlias​​]]
        Nothing happens. including printing
        echo $parent;
          • 3749
          • 24,544 Posts
          Are you sure the current resource has a parent and that the parent has an alias? Resources at the top level of the tree have no parent. I've amended the code above to test for that.

          echo $parent won't produce anything because $parent is an object, not a string.
            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
            • 37123
            • 186 Posts
            in fact he had not the resource parent ... I need to use that object in this way
            <meta tag description="[[!GetParentAlias]]" /> 
            how can I do? thanks!
              • 3749
              • 24,544 Posts
              In the code above, you can just replace "no parent" with whatever you want that meta value to be when there's no parent.

              If you want to be more document-specific, you can create a template variable called "MetaDescription" and connect it to your template(s).

              Then put this tag in the template:

              <meta name="description" content="[[*MetaDescription]]" />



              You can edit the TV for each resource to put whatever you want in it, and if you set the Input Options Value field of the TV to @INHERIT, children will inherit the value from the nearest ancestor with a value. [ed. note: BobRay last edited this post 14 years, 11 months ago.]
                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
                • 37123
                • 186 Posts
                thanks, but unfortunately I'm editing an existing site and I can not create a TV for that purpose. These days I try to apply the solution that you suggested me. thanks
                  • 33968
                  • 863 Posts
                  That's an invalid metatag, should be:
                  <meta name="description" content="[[*MetaDescription]]" />


                  Also it should contain a description of the page content rather than the page alias - are you sure you're modifying the right tag?
                    • 37123
                    • 186 Posts
                    yes yes, it's only an example...