Question about early parsed variables...
I am trying to be able to assign different statuses to channels if your logged in or logged_out.
I've tried with preload_replace which does not work.
So - I bought low variables because I read somewhere that you are able to put in logged_in or _out into a LV...
so this is my setup:
my variable name is: lv_logged_status
it set it on "enable early parsing"
variable type: "Textarea" (use code formatting)
The content of the variable is:
{if logged_in}not closed{/if}{if logged_out}open{/if}
so the variable seems to take the good value.
BUT: I would like to use it as a parameter of the channel:entries loop:
{exp:channel:entries channel="{var_channel}" status="{lv_logged_status}"}
but it does not work?!
so when exactly is the LV early parsed variables parsed... this must be after embed:stuff...
would such a thing be possible in any case?
cheers
stefan
Replies
Low 2 Apr 2012 16:45
Hi Stefan,
"Parsing variables" in this case simply means replacing the marker (for example {lv_logged_status}) with its content (in your case the two {if} statements). Note that the content of the variable is not parsed -- that is done by EE itself.
Now, if you take that into account, this is what you end up with as an opening tag, after the variable has been parsed (ie. replaced):
As you can see, the advanced conditionals are still in place, and not resolved until after the exp-tags are parsed. This is why your approach won't work.
To make sure it does work, we need to get rid of the logged_in/out conditionals altogether. Low Variables allows you to register the {logged_in_...} variables as early parsed vars, thus making it possible to use them in simple conditionals. (make sure you've got the option enabled in the extension settings)
The variable {logged_in_member_id} will be 0 if a user is not logged in, and a positive integer if the user is logged in. Therefore, you can use this variable to check whether the user is logged in or not.
Now, create 2 early parsed vars for the statuses:
lv_status_members => 'not closed'
lv_status_guests => 'open'
Then, you could use simple conditionals and preload replace variables to get the one you need:
The conditional above is a simple one, as long as you have the setting I mentioned earlier enabled. If the user is not logged in, the first preload_replace statement will be removed before they are processed. If the user is logged in, the first statement will take precedence over the second one, thus overriding it.
Hope that helps.
outline4 2 Apr 2012 17:08
thank you so much!
now I understand the whole process...
I thought that if I enable "early parsed" the content would also be executed early.
your {logged_in_...} setting in the extension saved my day!!
this is exactly what I needed!
thank you so much - I've tried to achieve this for so long!
a question though, and I hope you are not offended.
now that I know how this works. I plan to use this in the future.
for most of my projects LV is a bit overkill, and for those where I don't use LV it would be nice to only have the {logged_in_...} stuff as early parsed variables.
would you consider to release a cheaper add-on with just the {logged_in_...} stuff vs. extension/module...?
this would be awesome!
cheers
stefan
Low 3 Apr 2012 07:38
You're free to ask, of course. However, I'm not planning on separating the add-on into smaller chunks. You will find lots of other uses for LV once you get to know it more, so maybe the overkill bit isn't all that bad. :)
You can also look on Devot:ee for other add-ons that might offer similar functionality but less.
outline4 4 Apr 2012 10:34
Hi low,
I think your add-on is the only one with that functionality.
well never mind, I don't mind paying the extra bucks if the project scope allows it...
thanks anyways
stefan
outline4 12 Apr 2012 10:17
hi low,
I just found out that I made a really stupid mistake: I didn't really test this when I was logged out :(
in fact: this method doesn't work... it was too good, but only in theory :(
it always takes the value of {lv_status_members}. the inside of the first conditional is always parsed, so even if there's a second pre_status, it is NEVER taken into account!
please try it for yourself (logged_in, and logged_out).
I have the newest version of EE and Low Variables
Oh... I am sooooo sad...
how could I not test this thoroughly?
now: I even tested this:
{if logged_in_member_id > 0}
{preload_replace:pre_status="open|Draft"}
{/if}
{preload_replace:pre_status="open"}
{exp:channel:entries status="{pre_status}"}
which does not work as well...
*sniff*
Low 12 Apr 2012 10:34
Okay, try this slightly different approach:
Just tested this successfully.
outline4 12 Apr 2012 11:02
are you sure you tested this on an entry that has the status set to draft?
because my pre_status is always set to open now.. logged_in or logged_out...
same issue as before...
outline4 12 Apr 2012 11:04
I have low variables 2.1.0 and EE 2.4...
hm?
Low 12 Apr 2012 11:05
Ah, please update to LV 2.1.1. There was a bug in 2.1.0 concerning those vars.
outline4 12 Apr 2012 11:17
ahhh....
and it suddenly all works out again!
uff - I was a bit afraid, that even YOU, the master of parse order, is making errors...
but - my bad!
thanks again!
maybe you want to give your opinion over at http://themetaq.com/articles/a-better...
I think your method is even better!
outline4 12 Apr 2012 12:11
I've even put
{if logged_in_member_id == '0'}
{preload_replace:pre_status="open"}
{/if}
{preload_replace:pre_status="open|Draft"}
into an early parsed global (low) variable called lv_logged_detection...
now I only have to write:
{lv_logged_detection}
and then I am able to use {pre_status} to my liking!
hell yeah!
s*
Low 12 Apr 2012 12:13
Excellent work, mate.
martind 7 Jan 2013 07:40
shouldn't this approach also work like this?
{if logged_in_group_id == '0'}
{preload_replace:pre_status='open'}
{/if}
{if logged_in_group_id == '1' OR logged_in_group_id == '10' OR logged_in_group_id == '9' }
{preload_replace:pre_status='open|Draft'}
{/if}
cheers,
martin
Low 7 Jan 2013 08:03
Actually, having that second (advanced) conditional there has no effect at all.
martind 7 Jan 2013 09:39
thank you. So, is there another way to realise member group based statuses? Do only the advanced conditions not work?
Low 7 Jan 2013 10:39
Only if you're more verbose and use simple conditionals, so 1 conditional for each member group. As soon as you use OR in a conditional, it's an advanced one, so the preload_replace stuff will already be parsed before the conditional is processed.
martind 7 Jan 2013 10:46
ok, thanks for the quick feedback. Works as expected with the simple conditional.