1

I'm having a strange issue (possible bug?) with the following (simplified) code

{if segment_1 == ""}

//Do Stuff//

{if:else}

{exp:channel:entries limit="1" status="Open" url_title="{segment_1}" dynamic="no" parse="inward"}

    {!-- If no results then paramater must be a category for product listing --}
    {if no_results}
        {exp:gwcode_categories cat_url_title="{segment_1}" parse="inward"}

            //Do Stuff//

            {if no_results}
                {redirect="404"}
            {/if}

        {/exp:gwcode_categories}


    {/if}

    ///Do Stuff///


{/exp:channel:entries}

{/if}

The problem is with the 404 redirect. If I set 404 page to none in the backend it correctly redirects to a default page saying: "Status: 404 Page Not Found"

However when I change the 404 setting in the backend to show a custom template, it redirects to the 404 page, regardless of whether a category is found by gwcategories or not, ie no results always ends up being true, or is not correctly parsed.

I've tried a number of permutations of the no results conditional, eg: using

{if {results_total} != 1}{redirect="404"}{/if},

which doesn't work either. Even though testing the output of {results_total} outputs 1, it still redirects.

Anyone got any ideas?

  • I've found a temporary solution by editing the output for 404 errors in libraries/Template.php, but this is not a good solution. – RiaanZA Oct 15 '13 at 13:41
1

This is happening because of the first parse="inward". You're telling to the exp:channel:entries to parse everything before its inside other modules variables. So, the inner if no_results is parsed before the exp:gwcode_categories.

Actually, I can't see the point of adding any of the parse parameters. The segment variables will be parsed before the modules and plugins in any case.

{if segment_1 == ""}

//Do Stuff//

{/if}
{if segment_1}

    {exp:channel:entries limit="1" status="Open" url_title="{segment_1}" dynamic="no"}

        {!-- If no results then paramater must be a category for product listing --}
        {if no_results}
            {exp:gwcode_categories cat_url_title="{segment_1}"}

                //Do Stuff//

                {if no_results}
                    {redirect="404"}
                {/if}

            {/exp:gwcode_categories}

        {/if}

        ///Do Stuff///

    {/exp:channel:entries}
{/if}

I also turned your advanced conditional into two simple ones to prevent the second part to be parsed without need.

| improve this answer | |
  • I've tried your solution, but it didn't solve the problem, everything worked as before after removing the parse="inward" though, so it clearly wasn't needed. The strange thing to me is still that it works correctly as soon as I set the 404 template to none. Also thanks for the tip with the conditional :) – RiaanZA Oct 16 '13 at 7:01
  • This looks like a conflict. I can't read the code of the template parser class right now. Do you mind of to test something? Try to move the exp:gwcode_categories into an embed. I update my answer later. – Robson Sobral Oct 16 '13 at 14:05

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.