We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6531
    • 154 Posts
    I borrowed some code from [[Personalize]] to use in a snippet. I want to include some stuff ONLY if user is logged in:
       if ($modx->user->hasSessionContext($modx->context->get('key')) )

    But it’s showing it regardless. What am I missing??

    Here’s the full snippet:

    <?php
    $output = '';
    $albumData = unserialize(file_get_contents("http://vimeo.com/api/v2/album/$albumID/videos.php"));
    
    $output .= '<div id="albumGallery">
    ';
    foreach ($albumData as $vid) {
       $output .= '   <div id="albumGalleryItem">';
       $output .= '<a href="'.$vid['url'].'" title="'.$vid['title'].'" rel="zoombox[group]">';
       $output .= '<div class="ImgContainer"><img src="'.$vid['thumbnail_medium'].'"></div>';
       $output .= '<div id="albumGalleryCaption">'.$vid['title'].'</div>';
       $output .= '<div id="albumGalleryDescription">'.$vid['description'].'</div>';
       $output .= '</a>';
       if ($modx->user->hasSessionContext($modx->context->get('key')) ) {
          $output .=  '<a class="button" href="'.$vid['url'].'/settings/thumbnails">Change Settings</a>';
       }
       $output .= '</div>
    ';
    }
    $output .= '</div>';
    
    return $output;​
      • 22303 MODX Staff
      • 10,725 Posts
      I assume you are calling the Snippet non-cacheable?
        • 6531
        • 154 Posts
        Good point. That would defeat the purpose -- I want it cached except when logged in.
        So I made two versions of the snippet, which are called from inside a [[!Personalize]] call.