Early parsed variable to set 'status'?
Just getting started with LV, so I might just be missing something obvious.
I'm thinking of enabling LG Live Look, but don't want to duplicate all of my templates, to create a 'preview' template. I am trying to detect the logged in member's member_group, and if they are super admins, add my "Preview" status to the weblog:entries tag.
So, by default I have:
.... status="Open" ....
but would like an early parsed variable injected there:
.... status="Open|{var_status_preview}"
with the Low Variable containing the following:
{if member_group == '1'}|Preview{/if}
Can LV run code like this, so that the weblog:entries tag will respect that second status? Tried but it's not working.
Don't know if I'm using it wrong, if member_group isn't available by the 'early parsing' stage, whether the low Var is processed early enough...
Any ideas? Tx!
Replies
Low 26 Mar 2010 08:43
Hi Ira,
First, I'll explain roughly when EE variables are parsed (see also the Parse Order wiki article).
1. Early parsed vars (like path.php vars)
2. Regular template parsing ({exp:low_variables:parse})
3. Regular global vars (like the User Defined Template vars)
With your code, you're actually using a var parsed at stage 1 to display another var that will be parsed at stage 3 (the {if member_group} conditional, which should be {group_id}, by the way). So this results in having the literal string of the conditional as a tag parameter value. That's why it doesn't work.
Low Variables will not do any 'pre-parsing' of tags within the variable before outputting its value. Instead it works just like a string replace.
The only way I can think of to get the behaviour you're after, is by using PHP on input in the template. Something like this:
<?php
global $SESS;
$status = 'Open';
if ($SESS->userdata['group_id'] == '1'):
$status .= '|Preview';
endif;
?>
{exp:weblog:entries status="<?=$status?>"}
...
{/exp:weblog:entries}
Note: GetSatisfaction's code formatting is messing my code up a bit.
It's $SESS->userdata['group_id'], without the question mark in the middle.
ira42 26 Mar 2010 12:58
Hi Low,
Thanks for the thorough explanation!
I actually came to the same conclusion when running some tests... I ended up adding similar php, but into a Low Variable. Didn't work right away, until I set the display template to "Allow PHP on Input", and then it worked fine.
Definitely not ideal (there are many templates, embeds,etc), so I will need to consider building an extension, which automatically modifies the weblog status automatically.
Thanks again!
Ira
EDIT: Oh, and "member_group" is actually an accepted alternative to group_id, at least when used as a global variable.