We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36931
    • 206 Posts
    Dear All,
    I loosing my time tryinf to do somethin very easy::::::::

    I am calling a snippet called DateFR with a value (month of a date)
    [[+headingLabel:date=`[[DateFr? &mois=`%m`]] %Y`]]

    In my snippet, I get the mois value.
    I check if the vaiable is not empty, and I send the value to a function.

    My problem is that he does not reconize my value of the variable $month.
    if you echo $mois, it display 12, but the switch display "Mois introuvable" instead of Décembre.

    but you set the $mois to 12, it work


    echo $mois // It display 12

    $mois =12 //If you add this, it works, if you remove it it does work any more, even if echi $mois display well 12

    <?php
    $mois = isset($mois) ? $mois : $mois="";
    
    function moisAff($mois) {
        switch ($mois)
        {
            case ("01"): $moisaff = "Janvier"; break;
    	case ("02"): $moisaff = "Février"; break;
            case ("03"): $moisaff = "Mars"; break;
            case ("04"): $moisaff = "Avril"; break;
            case ("05"): $moisaff = "Mai"; break;
            case ("06"): $moisaff = "Juin"; break;
            case ("07"): $moisaff = "Juillet"; break;
            case ("08"): $moisaff = "Août";	break;
            case ("09"): $moisaff = "Septembre";break;
            case ("10"): $moisaff = "Octobre";break;
    	case ("11"): $moisaff = "Novembre";break;
    	case ("12"): $moisaff = "Décembre"; break;
    	default : $moisaff="Mois introuvable";
    
        }
    
        return $moisaff;
    }
    
    
    if($mois == ""){
    	echo "Aucun mois spécifié (Snippet DateFr)";
    }else{
    	echo moisAff($mois);
    }
    


    Someone know why happen?
    Will you free to ask me more detail

    Cheers
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The %m is only for formatting the output of the PHP strftime() function, which is how the date output modifier works. %m by itself as a snippet property is meaningless.

      You should simply be able to use %B %Y in the placeholder's modifier, if your locale is set correctly. I presume that headingLabel's value is a timestamp?

      If for some reason you do need to return the month of a given timestamp from a snippet as you are doing, pass the timestamp as a property and use strftime('%m', $timestamp) inside the snippet code.

      http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29#InputandOutputFilters%28OutputModifiers%29-Stringoutputmodifiers
      http://php.net/manual/en/function.strftime.php
      http://php.net/manual/en/function.setlocale.php

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 36931
        • 206 Posts
        Hello,
        I am sorry, but I dod not understand well.

        Here is my chunck called "tplMonth"
        <span class="label">[[+headingLabel:date=`[[DateFr? &mois=`%m`]] %Y`]]  | </span>
        

        Here is a snippet called "DateFr";
        <?php
        
        $mois = isset($mois) ? $mois : $mois="";
        echo $mois; // This disply 12
        echo strftime('12', $timestamp); //This display 12
        echo strftime($mois, $timestamp) // THis display 01?????????
        
        


        I do not udnerstand why the fiest display 12, and the last display 01, while echo $mois display 12.

        I did noit understand your comment.
        Thank for your help
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          If you need your dates to be in French, why don't you set the locale in the System Settings? Then MODx will do it automatically. You can just use :date=`%B %Y`


            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 36931
            • 206 Posts
            Quote from: sottwell at Dec 08, 2012, 01:45 PM
            If you need your dates to be in French, why don't you set the locale in the System Settings? Then MODx will do it automatically. You can just use :date=`%B %Y`


            Ho yes, I searches for this but I have not found it...
            I changed the setting "date_timezone" to Europe/Zurich but it did not work. May be I am wrong
              • 36931
              • 206 Posts
              Ok, I found it, and I lost so many time shocked(

              I set fr_CH to "local" setting.

              The last problem is I got that d�cembre 2012, with � shocked(, may be is du to the snippet I download. I search for that issue....

              Tks
                • 36931
                • 206 Posts
                Yes but unfortunately, I can not dot that.
                I am using the Add-on mxcalendar and may be there is something wrong with.
                I could get the day in french by changing a setting to fr.
                But it did not affect the date of the month. It display December 2012.
                If I set fr_CH to "local" setting, it display d�cembre 2012 and morever, there is a bug with the day. The day are now displayed like this : mxcalendars.label_vendredi

                Then I have to but back my configuration and search again and find a solution for this
                $mois = isset($mois) ? $mois : $mois="";
                echo $mois; // This disply 12
                echo strftime('12', $timestamp); //This display 12
                echo strftime($mois, $timestamp) // THis display 01?????????
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  What is your charset setting? It should be utf-8.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 36931
                    • 206 Posts
                    Quote from: sottwell at Dec 08, 2012, 02:28 PM
                    What is your charset setting? It should be utf-8.
                    It is. I checked it