We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20014
    • 200 Posts
    I have set up personalize with this call on a private page for clients
    here’s the call
    [[Personalize? &yesChunk=`colclient` &noChunk=`Register` &ph=`uid`]]


    on the client page I have been able to customize the text using UID, all the navigation menus will be the same for all the clients except areas for billing and website preview (where they can check out a site as it’s being developed)

    My question is this, how can I tell Personalize if it is client A to show this chunk and if it is Client B to show that chunk?

    also I have been playing around with if else, it’s been extremely useful in a thousand different ways using document object ID,

    <?php
    $id = $modx->documentObject['id'];
    if ($id=="33")
      $output="{{thischunk}}";
    elseif ($id=="32")
       $output="{{thatchunk}}";
    else
       $output="{{thischunk}}";
    return "$output";
    ?>


    is there anyway to base it on registered users? would I do it like this (I know this isn’t right because i don’t believe uid is a document object, but am I on the right track?):

    <?php
    $username = $modx->[+uid+];  
    if ($username=="A")
      $output="{{thischunk}}";
    elseif ($username=="B")
       $output="{{thatchunk}}";
    else
       $output="{{thatchunk}}";
    return "$output";
    ?>
      • 4041
      • 788 Posts
      This will set $username as the current logged in users username, otherwise empty.

      <?php
      $username = isset($_SESSION['webShortname']) ? $_SESSION['webShortname'] : ''; 
       
      if ($username=="A")
        $output="{{thischunk}}";
      elseif ($username=="B")
         $output="{{thatchunk}}";
      else
         $output="{{thatchunk}}";
      return "$output";
      ?>


      A quick snippet I use to print out the $_SESSION to can see what info is available to use:
      Create a new snippet with the code below, named whatever you want, and call it uncached on your page.
      <?php
      // session info
      $output ='';
      $output .='<p>'.print_r($_SESSION).'</p>';
      return $output;
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 20014
        • 200 Posts
        really great Breezer, that is a major keeper!!!!
          • 20014
          • 200 Posts
          sorry if I am about to take advantage of your generosity,the snippet worked perfectly, but it then occurred to me that I would want to combine both user id and document id to put out a chunk.

          I’ve scoured the php manual, Bob’s site and scroogled like crazy, and though there is a wealth of info, it is waaaaay over my head about combining arrays and strings, I try to do things intuitively but when it comes to php and javascript, you really have to know what you’re doing...(or at least have more gray matter than myself). I must have created four or five snippets with disastrous results.

          the reason I ask is if I have a multilingual site, and I want user A to see one chunk on a page that is English, but see another chunk on a page that is Spanish, how would I go about combining those?

          I know I should probably start powering out some books and get involved in some php forums, it’s just there seems to be quite a bit of coders talking here about resolving problems with regards to code being implemented on MODX. ...if you tell me to p**s off, I’ll understand. embarrassed laugh laugh

            • 4041
            • 788 Posts
            Maybe this will help to give you a starting point smiley

            <?php
            $output ='';
            
            // get the current document id
            $doc_id = $modx->documentIdentifier;
            
            // set up a couple of arrays with document id's
            $doc_array_1 = array('1','3','5','7');
            $doc_array_2 = array('2','4','6','8');
            
            // get the logged in username
            $username = isset($_SESSION['webShortname']) ? $_SESSION['webShortname'] : '';
            
            if($username =='A'){
                if(in_array($doc_id, $doc_array_1)){
                    $output .='{{Chunk_A}}';
                }elseif(in_array($doc_id, $doc_array_2)){
                    $output .='{{Chunk_B}}';
                }else{
                    $output .='{{default_chunk}}';
                }
            }elseif($username =='B' && in_array($doc_id, $doc_array_2)){
                $output .='{{Chunk_B}}';
            }else{
                $output .='{{default_chunk}}';
            }
            
            return $output;
            ?>
              xforum
              http://frsbuilders.net (under construction) forum for evolution
              • 20014
              • 200 Posts
              Sorry been really busy getting ready to deploy...
              Breezer, I don’t know what to say, but thank you so much! That went way above the call of duty!!
              There are so many things that a designer needs to implement for a basic web2.0 site now, static sites are almost dead except for the occasional small business owner with almost no money set aside in the war chest for a website.

              And though a cms such as drupal has a variety of click to install features, the flexibility just isn’t there and I am not really gaining much knowledge other than my dominance of CSS, php and javascript understanding has to be added to a designer’s arsenal if they are going to succeed.

              the power of modx to me is actually making me learn the concepts of the code I am working with, it’s bits and pieces of information such as that which is really helping me rock and roll...I am taking baby steps in combining these concepts but that single piece of info you just threw down just picked me up on my feet, the logic is becoming clearer and clearer...thanks a ton!!