We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13730
    • 149 Posts
    I am trying to get the number of the month with the @EVAL binding function in a TV.

    I have TV named startingDate (date format) and another TV named numMonth (text format)

    I made a snippet to get the number of the month named month-number Ex:
    [[!month-number? &var=`[[*publishedon]]`]] it is working perfectly.

    But when I use the @EVAL binding like this in the TV numMonth :

    @EVAL return $modx->runSnippet('month-number',array('var'=>'[[*startingDate]]'));

    I get the number 12 which is from the date Wednesday, December 31, 1969

    I try with the [[*publishedon]] same result.

    I think I have not the right way to pass the parameter date in the @EVAL binding.

    Does someone could tell me my mistake?


    Thank for your help
      • 3749
      • 24,544 Posts
      month-number and var are not set when the TV value is evaluated. You don't really want an @EVAL TV. You can use an output modifier to show the month number. You'll have to install PHX is you're using MODX Evolution.

      Try this:

      [[*startingDate:strtotime:date=`%m`]]




      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 13730
        • 149 Posts
        Sorry,sorry, I usually always mention the version of Modx. I use Modx version 2.2 .

        - getResources 1.4.2
        - php 5.3.8
        - mySql 5.1.56

        My first language is French, I'll try to explain I what to do.

        Thank you for your answer, but I do not want to display the number of month, I want to filter the results of getResources by the number of the month.

        I have these ressources

        - Training
        - course 1
        - course 2
        - course 3
        - course n

        For each course
        Tv : startingDate | date format | Starting date fo a course | Enter by the user
        Tv : numMonth | text format | Number of the month of the starting date | calculate with @Eval Binding in the Tv

        I want to place the number of the month of the startingDate in numMonth Tv with @Eval Binding, and with getResources filter the resources by the numMonth Tv.

        Is it possible? Is it the right way to do that?

        Thank
          • 3749
          • 24,544 Posts
          Can't you just put the tag I posted above in the getResources tag where you need the month number?


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            • 13730
            • 149 Posts
            My initial call for getResource with no results was :

            [[!getResources? &parents=`33` &tpl=`tpl-promo-detail` &limit=`10` &includeTVs=`1`  &tvFilters=`numMonth==04` ]]


            and try

            [[!getResources? &parents=`33` &tpl=`tpl-promo-detail` &limit=`10` &includeTVs=`1`  &tvFilters=`[[*startingDate:strtotime:date=`%m`]]==04` ]]


            with no results

            Thank you for your patience
              • 28120
              • 380 Posts
              You also need

              &processTVs=`1`
                • 13730
                • 149 Posts
                Thank,

                I add &processTVs=`1`, but no result.

                [[!getResources? &parents=`33` &tpl=`tpl-promo-detail` &limit=`10` &includeTVs=`1` &tvFilters=`[[*startingDate:strtotime:date=`%m`]]==04` &processTVs=`1`]]



                [ed. note: jber last edited this post 14 years, 7 months ago.]
                  • 13730
                  • 149 Posts
                  I put

                   [[*startingDate:strtotime:date=`%m`]]


                  in my numMonth TV, and place my numMonth TV in the content field, I get the number of the month.

                  So I place my numMonth TV in my getResources call :

                  [[!getResources? &parents=`33` &tpl=`tpl-promo-detail` &limit=`10` &includeTVs=`1` &tvFilters=`numMonth==04` &processTVs=`1`]]


                  again no result
                    • 3749
                    • 24,544 Posts
                    I'm afraid tvFilters works on the raw value of the TV. Sorry if I led you down the wrong path. I didn't realize you were trying to use it with tvFilters.

                    You might consider either entering the numMonth TV value manually before saving the resource or creating a plugin connected to OnDocFormSave that sets it for you.




                    ---------------------------------------------------------------------------------------------------------------
                    PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                    MODX info for everyone: http://bobsguides.com/modx.html
                      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
                      • 13730
                      • 149 Posts
                      Thank you Bob, it was my first option to enter the value manually in the numMonth TV.

                      I'm not familiar with the plugin creation, I will read the section of your book on the subject.

                      Thank you again