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

Snippet return whitespace issue

Development and Programming

hbsinternet's avatar
hbsinternet
24 posts
9 years ago
hbsinternet's avatar hbsinternet

I have created a snippet name “abc” and added the below code:

{exp:member:custom_profile_data}
{exp:query sql="SELECT md.m_field_id_1 AS custom_field FROM exp_member_data AS md WHERE md.member_id = '{member_id}'" }{custom_field}{/exp:query}
{/exp:member:custom_profile_data}

When we are accessing this snippet “abc” in tempalte file it returns the value with both side whitespace.

Please check and advise

Thanks

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

Have you tried putting the template contents all on one line? That might get rid of the linebreak whitespace, if that’s what you’re seeing.

       
hbsinternet's avatar
hbsinternet
24 posts
9 years ago
hbsinternet's avatar hbsinternet

Yes, we had already did but found the same result with linebreak whitespace. Please check and advise

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

I’m not reproducing. When I format the snippet like this:

{exp:member:custom_profile_data}{exp:query sql="SELECT md.m_field_id_1 AS custom_field FROM exp_member_data AS md WHERE md.member_id = '{member_id}'" }{custom_field}{/exp:query}{/exp:member:custom_profile_data}

And then render it in a template like this:

test{test_snippet}test

There is no whitespace on either side of the snippet.

       
hbsinternet's avatar
hbsinternet
24 posts
9 years ago
hbsinternet's avatar hbsinternet

Thanks Kevin, Now it is fixed. We have seen lots of spaces or newline in snippet editors. We have removed it and added the code all on one line.

I was facing another issue to snippet if condition

My snippet “test_snippet” return to 10

If I use below code in “_header” template then it is not checking conditional

if{test_snippet == '10'} {/if}

We have parse it in below way then it works

{embed="ssi/_header" snippet_parse="{test_snippet}"}

Now in header template we have applied below code

if{snippet_parse == '10'} {/if}

then it is working

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

That’s not valid EE code, the if should be inside the braces. Even then, try this instead:

<pre><code>{if '{test_snippet}’ == ‘10’} {/if}

       
hbsinternet's avatar
hbsinternet
24 posts
9 years ago
hbsinternet's avatar hbsinternet

Hi Kevin

We have found following recommend, not wrapping variables in braces ({}) for example, do this:

{if my_snippet == "hello world"}

instead of these:

{if {my_snippet} == "hello world"}
{if "{my_snippet}" == "hello world"}

EE refrence url is https://docs.expressionengine.com/latest/templates/conditionals.html

Please check

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
9 years ago
Kevin Cupp's avatar Kevin Cupp

Yes that’s the recommendation but it does not seem to be working in this instance. There are some cases where it still doesn’t quite work to leave out the braces. But yes always try to leave them out first, it should work most of the time.

       
hbsinternet's avatar
hbsinternet
24 posts
9 years ago
hbsinternet's avatar hbsinternet

Thanks Kevin

       

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.