We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7131
    • 83 Posts
    dernier_recours Reply #1, 18 years ago
    I tried to use NewsPublisher in a way that a same document including a NewsPublisher snippet could publish in different folders depending on the user who is logged in.

    I tried a snippet I called testsnippet:
    $username=$modx->getLoginUserName();
    switch ($username)
      { 
      case "fr": $folder=11;break;
      case "am": $folder=13;break;
      default: $folder=0;
      }
    return $folder;


    I tried to imbricate this snippet into NewsPublisher, like this:
    [!NewsPublisher? &folder=`[!testsnippet!]` &makefolder=`1` &template=`Minimal Template` &showinmenu=`1` &aliastitle=`0` &formtpl=`fr_newspublisher_blog`!]


    However, MODx thinks that the snippets is just [!NewsPublisher? &folder=`[!testsnippet!] and the rest is rendered like text.

    Then, I tried to put the php code that returns the $folder variable, like this:
    &folder=`$username=$modx->getLoginUserName();switch ($username)  {  case "fr": $folder=11;break;  case "am": $folder=13;break;  default: $folder=0;  }return $folder;`


    Even though I’m logged as fr, the default value of $folder (0) is taken.

    So,

    1- Is it possible to imbricate snippets? How?
    2- Any idea what is going wrong with my code?

    Thanks!
      at the edge of dawn,
      you ask yourself if your shadow did follow you down
      all night long
      • 7131
      • 83 Posts
      dernier_recours Reply #2, 18 years ago
      I have found a dirty solution by hacking NewsPublisher. There is a cleaner solution for sure, but this is the best I can do for now...

      //Set to 1 if you want users in the switch below to publish in the corresponding folder
      $folderUser = (!isset($folderUser)) ? 1:0;
      if($folderUser==1)
      {
        $username=$modx->getLoginUserName();
        switch ($username)
        {
          case "fr": $folder=11;break;
          case "admin": $folder=13;break;
          default: $folder=0;
        }
      }
        at the edge of dawn,
        you ask yourself if your shadow did follow you down
        all night long