1

The Situation: I'm building a new feature for a wildlife-based charity. They want to spice up their donation form to include images of relevant animals based on how users have been browsing the site. If a user checked out a page about Animal-X, when they hit the donation form, there should be a big image of Animal-X as well as other info stored in a Matrix entry.

I didn't do the original build of the site, and the site's setup is a little different to what I'm used to: Each page starts with {embed:_templates/_standard} and then uses {exp:stash:set name="xxxx"} to set content. The template at _standard is full of standard mark-up interspaced with {exp:stash:get}'s for content areas. I suspect this setup might have something to do with why I'm running into problems but the fact is I'm not well versed enough in stash or EE (yet!) to be able to identify why :(.

The Problem: I'm organising all my data in a Matrix inside a channel/channel entry (Donation Page Controller). This contains:

  • Cause name (eg. 'animalx') This is what gets stored in the 'interest' session_variable
  • List of page URLs that should set this interest
  • Image of animal-x
  • Text to use on Donation page
  • Text to use on Thanks page

I've also tried using a matrix in a Low Variable, but that didn't get me any closer to success.

My code looks like this at its most basic:

On all pages:

{exp:channel:entries entry_id="178"} {!--access entry that contains data--}
    {donatable_causes} {!--matrix--}
        {if current_url == don_pages} {!--compare URL to matrix content's list of pages--}
            {exp:session_variables:set name='interest' value="{don_text}"} {!--set the session var--}
        {/if}
    {/donatable_causes}
{/exp:channel:entries}

I've tried a heap of different variations on this; storing it in a seperate template, embedding, stashing, snippets, gv's... From what I can tell, setting the session_variable fires before the if conditional. So I tried using a stash:set scope='user' instead and getting to parse at the end, but I was getting a similar result. :(. I've tried everything I can think of.

On the donation page:

{exp:channel:entries entry_id="178" parse="inward"}
    {donatable_causes}
        {if "{exp:session_variables:get name='interest'}" == "{don_text}"}
            {don_image}
        {/if}
    {/donatable_causes}
{/exp:channel:entries}

The Solution: Ideally I'd like to be able to store the 'interest' in a exp:session_variable, and then access it later when building the form page, using it to pre-select an option in a drop-down, which then lazy-loads in other components like the image or some-such.

Am I missing something completely obvious? Am I doing this in a completely stupid way? Should I just be using a URL segment to do this (/donate/Animal-X) and use the drop-down to just push people to different pages? Should I just be working around with PHP? I'm really stuck :(.

I'd be happy to use Mo' Variables, Stash, Session_variables, or Low Variables to accomplish this, or any mix of them.

Thanks you guys!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.