We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12151
    • 115 Posts
    hi there ... i’m trying to add a little functionality to add automatically incremeted tabindex tags to all my links within my template. i know that the concept is sound but i can’t get it to work:

    SetTabIndex snippet:
    global $TabIndex = 0;

    GetTabIndex snippet
    $TabIndex++;
    echo " tabindex=’".$TabIndex."’";

    at the top of my template i call SetTabIndex and in my links i call GetTabIndex

    the first instance of GetTabIndex increments the variable to 1, but all further calls also return 1

    what am i doing wrong? any ideas gratefully accepted smiley
      • 22303 MODX Staff
      • 10,725 Posts
      I assume you have turned caching of the page off. Confirm that, then: where have you defined this variable outside the scope of each snippet? Declaring something global doesn’t do a thing if that variable does not appear in a variable scope outside the current scope of the code. And accessing it in each scope at the same level (i.e. within the eval()’d snippet) isn’t going to help any either.

      Typically, I avoid globals altogether and either use static members of classes or I use placeholders to approximate globals across a request.