0

I'm using Stash in a few ways. First, as a layout template (.layout-account.html). Second, to get variables for testing. But I'm struggling with the final part.

I have two channels - Users (via Zoo Visitor) and Firms. I want the user to be able to edit their own firm via a safecracker form. There exists a Playa field within the Zoo Visitor channel called "Firm". It let's my client choose the correct firm that the user belongs to from the Firms channel.

I have a Low Variable called {lv_stash_get_firm_id}. This calls a {channel:entries} to get the value of the Playa field for their firm.

{exp:channel:entries channel="zoo_visitor" limit="1" author_id="{logged_in_member_id}" status="HCAA_Members-id5|Open" parse="inward"}
    {exp:stash:set name="firm_url"}
        {embed="includes/.get_firm" entry_ids="{member_firm_name:child_ids}"}
    {/exp:stash:set}
{/exp:channel:entries}

The template .get_firm looks like this:

{exp:channel:entries channel="firms" fixed_order="{embed:entry_ids}" fixed_order="0|{embed:entry_ids}" dynamic="no" disable="member_data|pagination|categories" status="not closed" parse="inward"}
{entry_id}
{/exp:channel:entries}

My template for manage-firm-info looks like this:

{embed="layouts/.layout-account" site_top="public_top" security="yes"}
{lv_stash_get_firm_url}
{exp:stash:main_content}
            {if last_segment == "success"}
                <p class="profile-update-success">Your information has been updated.</p>
            {/if}

            {exp:safecracker channel="firms" entry_id="42" return="/profile/{segment_2}/{segment_3}/success" parse="inward"}
                ... Stuff ...
            {/exp:safecracker}
{/exp:stash:main_content}

The .layout-account controls all of the header and footer stuff, etc., and also calls {exp:stash:main_content}

Everything works fine if I use:

{exp:safecracker channel="firms" entry_id="42" return="/profile/{segment_2}/{segment_3}/success"}

or (assuming the entry_id is in the URL)

{exp:safecracker channel="firms" entry_id="{segment_3}" return="/profile/{segment_2}/{segment_3}/success"}

But obviously that won't work as the entry_id won't be the same for each user. Also, I'd rather not show the entry_id in the URL as someone could then modify it and change someone else's firm.

So I thought I would try to use Stash to set the firm_id and them pass it into the Safecracker form like this: {exp:safecracker channel="firms" entry_id="{stash:firm_url}" return="/profile/{segment_2}/{segment_3}/success"}

However, that doesn't work.

If I add {exp:stash:firm_url} prior to the Safecracker form, it spits out the correct entry_id. So it's getting that far. But it's not getting to the Safecracker form as it gives me an error that I need a valid entry to edit.

I'm guessing this is a parsing or syntax issue but I just can't quite get there.

Any help or suggestions are greatly appreciated!!

2

If you want to pass a variable in a parameter to any EE template tag, you need to add parse="inward" to the tag. For example:

{exp:stash:set name="firm_id"}1{/exp:stash:set}

{exp:safecracker channel="firms" 
   entry_id="{exp:stash:firm_id}"
   return="/profile/{segment_2}/{segment_3}/success" 
   parse="inward"
}
...
{/exp:safecracker}

EDIT: another way you pass a variable to another tag is via a placeholder variable inside {exp:stash:parse}:

{exp:stash:set name="firm_id"}1{/exp:stash:set}

{exp:stash:parse}
    {exp:safecracker channel="firms" 
       entry_id="{stash:firm_id}"
       return="/profile/{segment_2}/{segment_3}/success"
    }
    ...
    {/exp:safecracker}
{/exp:stash:parse}

In either case, make sure the variable you are passing doesn't contain line breaks since those are captured too; E.g. this will fail when you try to pass as a parameter:

{exp:stash:set name="firm_id"}
1
{/exp:stash:set}

If you want to remove line breaks automatically, use the trim="yes" parameter on either set or get:

{exp:stash:set name="firm_id" trim="yes"}
1
{/exp:stash:set}
| improve this answer | |
  • Hi Mark - thanks for your feedback. Actually, through my research I had found that I needed that (it's actually in my example above but just scrolled off the screen). I have tried both entry_id="{exp:stash:firm_id}" and entry_id="{stash:firm_id}. I've also tried entry_id="[{stash:firm_id}]" and entry_id="[{exp:stash:firm_id}]" because I saw an example while doing research. I just keep getting "You must specify a valid entry to edit" message. Yet if I drop {exp:stash:firm_id} above the safecracker, it gives me the firm_id. And if I put in "42" for entry_id, it pulls the correct info. :( – Todd Oct 2 '14 at 13:26
  • I just tried a simple {exp:channel:entries} and added {exp:stash:firm_id} as the entry_id. Even with parse-"inward", I'm not getting any results with that either. I've got to be over looking something somewhere! :( – Todd Oct 2 '14 at 18:01
  • Passing a variable like this definitely works, but there is another way to do it - see updated answer and also the note at the bottom – Mark Croxton Oct 3 '14 at 17:11
0

OK, so no matter what I did I couldn't get it to work as it was (even though it was outputting the correct value outside of the Safecracker form).

I came across another post and one thing someone said at the end was "I guess I was overthinking it." So I started to go back through and look at everything.

I was already getting a value for the permissions from the Zoo Visitor channel using

{exp:zoo_visitor:details}
    {exp:stash:set name="permissions"}{cf_member_firm_permissions}{/exp:stash:set}
{/exp:zoo_visitor:details}

So I added another call in there to get my firm_id

{exp:zoo_visitor:details} {!-- This finds out whether they are editor or not --}
    {exp:stash:set name="permissions"}{cf_member_firm_permissions}{/exp:stash:set}
   {exp:playa:children field="member_firm_name"}
        {exp:stash:set name="firm_id"}{entry_id}{/exp:stash:set}
   {/exp:playa:children}    
{/exp:zoo_visitor:details}

I was able to use entry_id="{exp:stash:firm_id}". The additional bonus is that it also saved me from having to run the extra embed to pull the entry_id from the Firms channel.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.