We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Channel entries with variables from super_cookie

How Do I?

hawkwynd's avatar
hawkwynd
9 posts
4 years ago
hawkwynd's avatar hawkwynd

I’m trying to get an entry from the partners channel based on the value stored in the super_cookies. It isn’t working. Can someone show me the correct way of doing this please?

Here’s the code:

{if {exp:super_cookies:get name="partner_id"} }
                
                {exp:channel:entries channel="partners" entry_id="{exp:super_cookies:get name='partner_id'}" limit="1" }
                    <div class="col">
                            {brand_logo}
                    </div>
                    <div class="col mbr_contact">
                         <div class="member_title_header">{title}</div>
                    
                    {if partner_phone}{partner_phone} <br>{/if}

                    {if contact_email}<a href="mailto:{contact_email}target=_blank" rel="noopener">{contact_email}</a><br>{/if}
                    
                    {if company_website}<span><a href="http://{company_website}target=_blank" rel="noopener">Visit Website</a></span>{/if}

                </div>
                {/exp:channel:entries}
            
            {/if}
       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

I’ve never used Super Cookies, but the first thing I would do is turn on the template debugger, then review where this channel entries loop is called and see if {exp:super_cookies:get name='partner_id'} I being parsed before the channel entries tag is parsed.

       
hawkwynd's avatar
hawkwynd
9 posts
4 years ago
hawkwynd's avatar hawkwynd

Strange - the template debugger is showing an odd value that isn’t the value in the cookie.

So, now I know why it’s not working. See the attached screenshot, the entry_id value should be 413. Not that long string of random characters.

Can I simply use PHP to read the cookie instead of using the exp:super_cookies addon?

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

So that means that something with the add-on is properly throwing an error or is not parsing correctly. If you know PHP, you can probably track it down in the add-on’s file.

You may also try adding parse="inward" to see if that’s the issue. So it would look like {exp:channel:entries channel="partners" entry_id="{exp:super_cookies:get name='partner_id' parse='inward'}" limit="1" }

You can enable PHP on the template and handle it that way if you want, but we typically recommend against enabling PHP unless needed. It’s often just as simple to create a super quick add-on to return the value you want instead of risking security issued by enabling PHP.

Few helpful links:

  • Changing the parse order with parse=”inward”
  • PHP in templates
  • Creating a basic add-on with template tags
  • Using the CLI to make generating that add-on even easier

Hope this helps.

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

fyi. I just had a few minutes to test on a local install with the default theme. For me, I needed to add parse="inward" to the exp:channels tag.
So it looks like this {exp:channel:entries channel='blog' limit='1' entry_id="{exp:super_cookies:get name='mycookie'}" dynamic="no" parse="inward"}

       
hawkwynd's avatar
hawkwynd
9 posts
4 years ago
hawkwynd's avatar hawkwynd

Andy - That worked perfectly! Thank you for your help!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.