1

I have a snippet

{exp:number_format number="{price}" decimals="2"  dec_point="." thousands_sep=","}
I use this snippet in two pages.

The weird thing about this is that in one page, it outputs correctly while in the other one does not.

For example, I passed 19000.00 in both of them.

In one page, I get 19000.00 but in the other one I got 0.00

UPDATE:

Ok I noticed that in the problem page, I am using Switchee while in the working page, I don't.

I tried changing the problem page to not use Switchee and it worked.

Does this mean that this is somewhat a parse order problem?

UPDATE 2:

Here is the sample code

{exp:switchee variable="{segment_2}" parse="inward"}
        {case value="#some regex expressions here#"}
            {exp:low_search:results 
            limit="10"
            channel="foo"
            paginate="bottom"
            status="open"
            parse="inward"}
        {/case}
        {case default="Yes"}
            {exp:low_search:results 
            query="{segment_2}"
            limit="10"
            channel="foo"
            paginate="bottom"
            status="open"
            parse="inward"}
        {/case}
    {/exp:switchee}
        ........
        <h2>{snippet.that.contains.the.number.format.code}</h2>
        ........
{/exp:low_search:results}

Here is the snippet code

${exp:number_format number="{price}" decimals="2"  dec_point="." thousands_sep=","} 

UPDATE 3:

I tried changing

 ${exp:number_format number="{price}" decimals="2"  dec_point="." thousands_sep=","} 

to

${exp:number_format decimals="2"  dec_point="." thousands_sep="," parse="inward"}{price}{/exp:number_format} 

in hopes of solving the problem. Unfortunately, it didn't work.

P.S.

For all intents and purposes, {exp:low_search:results} is functionally the same as {exp:channel:entries}

10
  • Are you using the switchee tag with "parse=inward" ? Feb 6, 2013 at 4:13
  • Yes, I am using it Feb 6, 2013 at 4:16
  • Yes, likely a parse order, can u throw up some simplified code so we can see where variables are being declared etc. Feb 6, 2013 at 5:36
  • I updated my question to include simplified code Feb 6, 2013 at 9:43
  • What's the primary difference between the 2 switchee cases ? Not being a Grand Master of parse orders and what not, I'd personally look at capturing the different variables required and move your opening {exp:low:results} tag outside the switchee then pass the variables to the {low:results}. Feb 6, 2013 at 10:26

2 Answers 2

1

This is more of a guide then a solution, experimentation is your friend.

{exp:stash:set parse_tags="yes"}
    {exp:switchee variable="{segment_2}" parse="inward"}
        {case value="my case value"}
            {stash:query}all{/stash:query}
        {/case}
        {case default="Yes"}
            {stash:query}{segment_2}{/stash:query}
        {/case}
    {/exp:switchee}
{/exp:stash:set}

Further down the template, ese the stash'ed variable holding the variable defined above as the query.

 {exp:low_search:results 
    query="{exp:stash:query}" // Whack the stash Var in here
    limit="10"
    channel="foo"
    paginate="bottom"
    status="open"
    parse="inward"}

      <h2>{snippet.that.contains.the.number.format.code}</h2>

  {/exp:low_search:results}

PS. You will need to install Stash obviously :)

3
  • Unfortunately, using stash is not an option. The code structure that I have is necessary because of stash parse order problems, Feb 6, 2013 at 11:00
  • Then without any further knowledge of how your code is wrapped, I'd look at embeds (stash or EE) between your case arguments. Its not the dryest solution but there appears to be more in play then you've outlined. Feb 6, 2013 at 21:50
  • I updated my question. Feb 7, 2013 at 4:42
0

I really believe your issue is with have the closing tag outside of the switchee cases. You can completely remove Switchee and use a simple conditional to show/hide the query parameter since it only seems to be on a unique case.

{exp:low_search:results 
  {if segment_2 != "something"}query="{segment_2}"{/if}
  limit="10"
  channel="foo"
  paginate="bottom"
  status="open"
  parse="inward"
}

Update

What if you nested Switchee in between the {exp:low_search:results}:

{exp:low_search:results 
    {exp:switchee variable="{segment_2}" parse="inward"}
        {case value="#some regex expressions here#"}
            limit="10"
            channel="foo"
            paginate="bottom"
            status="open"
        {/case}
        {case default="Yes"}
            query="{segment_2}"
            limit="10"
            channel="foo"
            paginate="bottom"
            status="open"
        {/case}
    {/exp:switchee}
}
4
  • I can't use native if else since the value that I am comparing to segment_2 are regex expressions Feb 7, 2013 at 6:16
  • Updated my answer to nest switchee between the opening tag
    – Siebird
    Feb 7, 2013 at 13:56
  • Your suggestion didn't work. I guess it might be that params parse order is different? Feb 8, 2013 at 2:24
  • I just realized I still had parse=inward in there. Try it without that parameter
    – Siebird
    Feb 8, 2013 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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