I'm a novice in ExpressionEngine, but with plenty of background in PHP. Still, I'm struggling with the EE parsing order.
Here is my situation and I would be very, very thankful if anyone can give me some/any guidelines how to approach it or what I'm doing wrong.
I'm having a page that renders some content and there is a link to reveal more. The trick is that revealing that more content is password gated, but with no membership complexity.
I've got a static password (yeah, I know) that is saved as a snippet. When the user clicks to reveal more content a dialog is shown, asking for the password and then the form posts to the same page.
When the page loads it checks to see if a session variable is set and if not, sets it, then re-directs to itself (to clean up the posted values).
The page re-loads and checks for the session variable. If it is set it displays the more content, otherwise displays the link to ask for password.
Here is the snippet. I've renamed the variables, so they make more sense.
{exp:switchee variable="{exp:session_variables:get name='session_variable'}" parse="inward"}
{case value=""}
{if '{post:posted_variable}' != '' AND '{post:posted_variable}' == '{snippet_variable}'}
{exp:session_variables:set name='session_variable' value='1'}
{/if}
{exp:redirectee:redirect status='302' url='{current_url}'}
{/case}
{/exp:switchee}
... Content ...
{if '{exp:session_variables:get name='session_variable'}' == '1'}
<p>... MORE CONTENT OF SOME KIND ... an embed/snippet even</p>
{if:else}
<a href="#password-modal">Click here to view More Content</a>
<div id="password-modal">
<form action="{current_url}" method="post"><input name="posted_variable" type="password" /><input type="submit" value="Go" /></form>
</div>
{/if}
... JS to handle the modal ...
My understanding is that EETemplate parses first the {exp}
tags, then the advanced {if}
, which made me use switchee with the parse="inward"
attribute. I used to have it in an {if}
conditional. Still the switchee case is not firing, and the previous setup always fired the session set and redirects.
Thanks in advance.
Third party stuff:
- Redictee - http://reinos.nl/add-ons/redirectee
- Session Variables - http://putyourlightson.net/session-variables-plugin
- Switchee - hallmark-design.co.uk/code/switchee/
- Mo Variables - github.com/rsanchez/mo_variables
EDIT:
In addition to the above. I've tried extracting the top code to separate page, and the form action sends the user there, which should redirect back. It's all using switchee, which looks very complicated for such a simple thing! It still doesn't work.
{exp:switchee variable="{exp:session_variables:get name='session_variable'}" parse="inward"}
{case value="1"}
{exp:redirectee:redirect status='302' url='{last_page_visited}?status=allok'}
{/case}
{case default="no"}
{exp:switchee variable="{post:posted_variable}" parse="inward"}
{case value="{snippet_variable}"}
{exp:session_variables:set name='session_variable' value='1'}
{exp:redirectee:redirect status='302' url='{last_page_visited}?status=good'}
{/case}
{case default="yes"}
{exp:redirectee:redirect status='302' url='{last_page_visited}?status=bad'}
{/case}
{/exp:switchee}
{/case}
{/exp:switchee}
For some reason {case value="{snippet_variable}"}
is never considered.
{case default="yes"}
is the only case that is considered. Simply setting it to {case default="no"}
breaks the page.
Any suggestions?