-
☆ A M B ☆
- 2,475 Posts
I’m using WebLoginPE to provide an interface to a site containing a members-only area... the one tricky bit is that the site requires that the sidebar displays the login form if you haven’t logged in, and a menu if you have. My thought was to use the Personalize Snippet so that the yesChunk contains the menu and the noChunk would contain the call to the WebLoginPE snippet... but that’s when I realized that the chunks referenced by the Personalize Snippet won’t parse any Snippets. Plain HTML is fine, but any Snippet calls in the yesChunk or noChunk won’t parse.
Am I doing something wrong? Is there a better way to do this?
Thanks!
Not quite sure why snippets won’t parse but you could make a snippet something like this (named whatever you like):
<?php
/* Menu_WebloginPE
[!Menu_WebloginPE!]
*/
$output ='';
// check if the user is logged in
if(isset($_SESSION['webShortname'])){
// if logged in, output the menu
$output .='{{YourMenuChunkName}}';
}else{
// if not logged in, show the login form
$output .='[[WebloginPE]]';
}
return $output;
?>
Of course you would change the "YourMenuChunkName" and add whatever params to the WebloginPE snippet call you use.
I think this will work
-
☆ A M B ☆
- 2,475 Posts
Thanks, Breezer, for the speedy reply (with code, no less!) -- we found a work-around... namely, we only use the yesChunk to display the menu. The WebLoginPE call displays the logout information in the sidebar once someone is logged in, and that’s acceptable for this particular project. I’ll try your solution if they have a problem with the existing workaround...
I have no problems putting the WLPE snippet calls in the personalize yes & no chunks in a sidebar. In fact, in the Personalize ’yes’ chunk, I have 2 snippet calls - the WebLoginPE snippet and SimpleCounter snippet. WebLoginPE 1.3.1 & Personalize 3.0
Everett, any chance the RTE was mangling the snippet calls?
-
☆ A M B ☆
- 2,475 Posts
Nope, RTE couldn’t have affected the Snippet calls because
1. it’s disabled for my user on that site and
2. the Snippet calls were in the chunk’s text, where there is no RTE.
I haven’t looked at this since I did my mock up, but I’ve noticed similar behavior at times with other Snippets that use chunks to format their output.
-
☆ A M B ☆
- 24,524 Posts
I haven’t actually looked at the code, but if it’s using getChunk or parseChunk, it gets the raw chunk content from the cache. Snippets etc. won’t have been processed.
function getChunk($chunkName) {
$t= $this->chunkCache[$chunkName];
return $t;
parseChunk only does some internal search-and-replace, it doesn’t correspond to the document parser in function.
-
☆ A M B ☆
- 2,475 Posts
That’s certainly consistent with what I’m seeing. If needed, I’ll crack open the code and write a version that parses the chunk instead of using the getChunk method. But if I can ride the work-around a bit longer, I will...
-
☆ A M B ☆
- 2,475 Posts
Wait... I think my fragile understanding just slipped... shouldn’t the MODx parser pick up any instances of {{chunks}} or [[Snippets]] if a Snippet prints that text as output?
I’m working on another Snippet where this might be an issue... it’s a case where I may not be able to realistically tie into the $modx->xyz methods.
Here’s a simple example: say my Snippet allows the user to specify a file to use as a template (the usage being similar to what normally might be defined as a Chunk). I can load up the contents of that file, and I can parse out my own placeholders (i.e. the one that my Snippet knows about)... but after that, I don’t want to dump the other [[Wayfinder]], [[Ditto]], et al Snippet calls back to the page and have them go un-rendered. I want them to be parsed.
Am I in for some trouble here? Is this all the result of the containing page being cached? I wouldn’t think so... but I as I said, my understanding just slipped a bit.
Thanks for any explanations.
Quote from: Breezer at Apr 15, 2009, 02:51 PM
Not quite sure why snippets won’t parse but you could make a snippet something like this (named whatever you like):
<?php
/* Menu_WebloginPE
[!Menu_WebloginPE!]
*/
$output ='';
// check if the user is logged in
if(isset($_SESSION['webShortname'])){
// if logged in, output the menu
$output .='{{YourMenuChunkName}}';
}else{
// if not logged in, show the login form
$output .='[[WebloginPE]]';
}
return $output;
?>
Of course you would change the "YourMenuChunkName" and add whatever params to the WebloginPE snippet call you use.
I think this will work 
Wow! Thank you! I have been trying to make something similar work with the Personalize snippet for hours now to no avail. This code worked the first time I tried it! I didn’t have to fiddle around with the parameters or anything. I’ve been reading alot of posts from people looking for a code that can do a logged in logged out display like this, so I hope they find this post like I did. Thanks.
Oh yeah. Here’s the site (incomplete) if anyone wants to see it action.
http://www.themovietimeline.net/modx/