We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36541
    • 222 Posts
    This is an auto-generated support/comment thread for GetField. Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Returns any document field (id, pagetitle, alias, etc.) or any template variable for:

    * any document
    * any of its parents up to a specified number of levels (eg. 2 levels up)
    * its ultimate parent (right under the document tree root)

    Author: Grzegorz Adamiak [grad]
    Version: 1.3 beta @2006-11-08 14:40:04
    License: LGPL
    MODx: 0.9.2.1+


    History:
    # 1.3
    - Distribution package is compatible with MODx Resource Wizard.
    - Applied MODx snippet coding guidlines from http://wiki.modxcms.com/index.php/Creating_Snippets.
    - changed variables and function names
    - variables get destroyed after use
    - moved functions to the external include
    - Created GetField.txt with history, links to documentation and repository and installation instructions.
    - Changed field fetching routine to always use gfGetFieldContent function.
    # 1.2.2
    - A quick fix to "Cannot redeclare function".
    # 1.2.1
    - Reworked fetching of template variable (again wink to enable output of widget.
    # 1.2
    - Reworked fetching of template variable value to get INHERITED value.
    - Removed defaulting to ’pagetitle’ when $field not found; this is due to fact hat tv can have empty value.
    # 1.1.1
    - Fixed small bug with $parentLevel and $topid check; now should work as expected.
    # 1.1
    - Reworked fetching of template variable value, now it gets computed value instead of nominal; however, still not the inherited value.
    - Changed license to LGPL.
    # 1.0
    - First public release.
      This is the web: the only thing you know about who will come is that you don't know who will come.
      • 16429
      • 254 Posts
      I’ve a problem with your snippet...

      I’ve a "Product catalog" folder containing "Brand" folders.
      Every "Brand" folder contains "Products" pages.

      I’ve setted up a page in news section where I use your snippet to insert a product in a highlight box.
      I can use your snippet to fetch data from a "Product" page with a call, and I want to call the snippet another time to fetch the pagetitle of the direct parent folder, the "Brand" folder, which is the brand of the product.

      If I call the snippet with $parent=’0’ it fetch the data from the ID i state in the call, but if I call the snippet with $parent=’1’ and $parentLevel=’1’ to fetch data from the direct parent (let’s say the "father") I obtain data from the "Product Catalog" page.

      I can’t obtain data from other pages than the ID page and the top parent (the one right under the root).

      This is my call
      [!GetField?docid=`[*iv_vino*]` &field=`id` &parent=`1` &parentlevel=`1`!]

      Note that I tried other combinations, but I got the ID page data or the top folder data only.

      Perhaps my explaining ins’t too much delightful, ask in case!

      Thanks
        kudo
        www.kudolink.com - webdesign (surprised?)

        [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
        • 36541
        • 222 Posts
        It should work as expected now. I updated repository with new version 1.1.1 which fixes this bug.
          This is the web: the only thing you know about who will come is that you don't know who will come.
          • 36541
          • 222 Posts
          I just updated repository with new version of the snippet - 1.2.

          The most important change is fetching the inherited value of template variable instead of default/nominal.

          Enjoy.
            This is the web: the only thing you know about who will come is that you don't know who will come.
            • 16429
            • 254 Posts
            From version 1.2 tvs with image widget return only data, not formatted TVs.

            So, instead of an image, it returns only the path.
              kudo
              www.kudolink.com - webdesign (surprised?)

              [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
              • 36541
              • 222 Posts
              Well, that was quite intentional as originally I had in mind only the variable data. Personally I don’t use widgets so the need to output them didn’t come to my mind. Anyway, in the repository you’ll find updated snippet which should output widgets. I didn’t have time to test it so please let me know if it works.
                This is the web: the only thing you know about who will come is that you don't know who will come.
                • 16429
                • 254 Posts
                Quote from: grad at Jul 19, 2006, 01:46 AM

                Well, that was quite intentional as originally I had in mind only the variable data. Personally I don’t use widgets so the need to output them didn’t come to my mind. Anyway, in the repository you’ll find updated snippet which should output widgets. I didn’t have time to test it so please let me know if it works.

                I thought you want this kind of result. You are right, I didn’t intend to make a request, only to point out this change.
                I agree with you to take only the TV data, but when it comes to output an image the image widget is very practical.

                Thanks anyway.
                  kudo
                  www.kudolink.com - webdesign (surprised?)

                  [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
                  • 15234
                  • 3 Posts
                  Hi!
                  Thank you for your nice snippet.

                  I am using v1.1.1 with php4/mysql4 -- no-problem.
                  There are three [getField] snippets in my template.

                  I moved my site to another hosting running with php5/mysql5.
                  MODx said,
                  "fatal error, gettv() already declared"

                  In order to fix it, I remove function"gettv()" like this.
                  [tt]if (!$output)
                  {
                  $op = $modx->getTemplateVarOutput($field,$docid);
                  $output = $op[$field];
                  // not found among TVs
                  if (!$output)
                  {
                  $output = $docFields[’pagetitle’];
                  }
                  }[/tt]

                  I am new to php5, so I do not know this workaround is right or wrong...
                  I hope this info will help you. Thanks!
                    • 36541
                    • 222 Posts
                    Thanks for your input.

                    I haven’t tested any release of getField with PHP5 (I use 4.4.0) so I can’t provide support for it. Anyway, I took a quick look at your workaround and compared it to the latest 1.2.1 (which seems to be final one at the moment) and I think 1.2.1 should work with PHP5. Please test it.

                    The 1.2.1 works exactly the same way as 1.1.1, but additionally it returns the INHERITED values of template variables and supports using widgets to format tv’s output.

                    1.2.1 should also work with the latest MODx 0.9.5 beta, however I haven’t tested it yet. Due to some changes in MODx I think I would make a new release once 0.9.5 is out.
                      This is the web: the only thing you know about who will come is that you don't know who will come.
                      • 25663 MODX Staff
                      • 12,272 Posts
                      095 is functionally and basically feature complete. You should be able to make a new release based on the public betas. Thanks for contributing. smiley
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me