Announcement

Collapse
No announcement yet.

variable within a variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    variable within a variable

    Is it possible to use a variable within a variable?

    For instance, in this token, &mvt:subcats[18]:code; I would like to use a variable for the number (in this case 18).

    So, is it possible to have it function like: &mvt:subcats[number]:code;

    Using toolkit, I created a random number variable and tried using it like this:
    <mvt:item name="toolkit" param="vrandom|number|l.all_settings:subcat_count" />
    &mvt:subcats[number]:code;

    However, no go.

    Is there a way to do this?

    Thanks.







    #2
    When using Tool Kit in this way, 'number' is a global variable. Try this as your token:
    Code:
    &mvt:subcats[&mvt:global:number;]:code;
    Matt Zimmermann

    Miva Web Developer
    Alchemy Web Development
    https://www.alchemywebdev.com
    Site Development - Maintenance - Consultation

    Miva Certified Developer
    Miva Professional Developer

    https://www.dev4web.net | Twitter

    Comment


      #3
      Hi Matt,

      Thank you for the response.
      Yes, I had already tried that. Here is the error message:
      Fatal error in mm5/5.00/templates/s01/c51-footer.mvc @ [00000002:0000005c]: modules/component/cmp-cssui-pchdft.mv: Line 4: Array index must be positive integer

      Comment


        #4
        Check to make sure that &mvt:global:number; is outputting. If it isn't, you may need to check the variable being used to generate the random number.
        Matt Zimmermann

        Miva Web Developer
        Alchemy Web Development
        https://www.alchemywebdev.com
        Site Development - Maintenance - Consultation

        Miva Certified Developer
        Miva Professional Developer

        https://www.dev4web.net | Twitter

        Comment


          #5
          It is outputting.
          &mvt:global:number; does show a number value.

          Comment


            #6
            Can you post the function you are passing the global number into?
            Matt Zimmermann

            Miva Web Developer
            Alchemy Web Development
            https://www.alchemywebdev.com
            Site Development - Maintenance - Consultation

            Miva Certified Developer
            Miva Professional Developer

            https://www.dev4web.net | Twitter

            Comment


              #7
              <mvt:item name="toolkit" param="vrandom|number|l.all_settings:subcat_count" />
              &mvt:global:number;
              <br>
              &mvt:subcats[&mvt:global:number;]:code;

              Comment


                #8
                Are you using this within a Tool Kit function or is it just for displaying the particular code?
                Matt Zimmermann

                Miva Web Developer
                Alchemy Web Development
                https://www.alchemywebdev.com
                Site Development - Maintenance - Consultation

                Miva Certified Developer
                Miva Professional Developer

                https://www.dev4web.net | Twitter

                Comment


                  #9
                  I am using it in a ReadyTheme Product Listing (carousel).
                  I have also tried it on the footer of a category page.
                  In both cases I do get a value for &mvt:global:number;

                  Comment


                    #10
                    It looks like, at this time, without using something like Tool Belt, Miva will not render a variable within a variable like you are trying to do. You can see an example of how to use the assign function in Tool Belt here, see example 4 http://www.pcinet.com/p/toolbelt_docs.html#Assign
                    Matt Zimmermann

                    Miva Web Developer
                    Alchemy Web Development
                    https://www.alchemywebdev.com
                    Site Development - Maintenance - Consultation

                    Miva Certified Developer
                    Miva Professional Developer

                    https://www.dev4web.net | Twitter

                    Comment


                      #11
                      What if you tried something like this?

                      Code:
                      <mvt:eval expr="l.settings:subcats[g.number]:code" />
                      David Carver
                      Miva, Inc. | Software Developer

                      Comment


                        #12
                        Thanks dcarver,

                        Tried it but the same error.

                        Comment

                        Working...
                        X