2

I didn't think this would give me any trouble, but it is. I just want to run a query depending on the URL segments.

I have this now:

        {if segment_3 != ''}
            {exp:query sql="SELECT a.cat_id, a.parent_id, b.cat_name FROM exp_categories a, exp_categories b WHERE a.cat_url_title = '{segment_3}' AND b.cat_url_title = '{segment_2}'"}
        {if:else}
            {exp:query sql="SELECT cat_id, parent_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
        {/if}
            ...
        {/exp:query}

But every time I wrap it in the IF statement, I get nothing...

1 Answer 1

5

This happens because of the "else". If you use else, the conditional became advanced and it will be parsed after the modules.

Try this:

{if segment_3 != ''}
   {exp:query sql="SELECT a.cat_id, a.parent_id, b.cat_name FROM exp_categories a, exp_categories b WHERE a.cat_url_title = '{segment_3}' AND b.cat_url_title = '{segment_2}'"}
{/if}
{if segment_3 ==''}
    {exp:query sql="SELECT cat_id, parent_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
{/if}
        ...
{/exp:query}
0

Your Answer

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

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