0

Hi I'm looking for a way to repeat this process to build a title with conditionals

In the php version of my site I can use the following

if (!empty($PostKeyword)) {
    $PostTitle = $PostKeyword." Jobs";
    if (!empty($PostLoc)) {
        $PostTitle = $PostKeyword." Jobs in ". $PostLoc;
    }
} elseif (!empty($PostCategory)) {
    $PostTitle = $PostCategory." Jobs";
    if (!empty($PostLoc)) {
        $PostTitle = $PostCategory." Jobs in ". $PostLoc;
    }
} else {
    $PostTitle = "Jobs In ". $PostLoc;
}

I was hoping this could do the same with this in EE but it just throws errors

{if {super_search_keywords} !=""}

    <h1>{super_search_keywords} Jobs</h1>

{if:elseif super_search_category_name !=""}

    {if {super_search_job_location} !=""}
        <h1>{super_search_category_name} Jobs In {super_search_job_location}</h1>
    {/if}

    <h1>{super_search_category_name} Jobs</h1>

{if:else}

    <h1>Jobs In {super_search_job_location}</h1>

{/if}

Sorry for the look I cant find a way to format this nicely

  • Which errors? Please, add them to your question. – Robson Sobral Nov 14 '13 at 20:17
  • If I searched with a category and location the page wouldn't load and I'd get Parse error: syntax error, unexpected T_IS_NOT_EQUAL in /home/jobsonli/public_html/addon/jobsarena.co.uk/jobsysonline/expressionengine/libraries/Functions.php(679) : eval()'d code on line 5 – Anthony Ifon Nov 15 '13 at 14:08
3

The error happens because, sometimes, the conditionals brakes after a stage of parsing. Example:

{if {x} != ""}

If, x is empty, the conditional will be turned into:

{if != ""}

Which doesn't make sense.

So, you can use:

{if "{x}" != ""}

Or the what the Template Class calls "short conditionals":

{if x}

I suggest you to try:

{if "{super_search_keywords}" !=""}

    <h1>{super_search_keywords} Jobs</h1>

{if:elseif "{super_search_category_name}" !=""}

    {if "{super_search_job_location}" !=""}
        <h1>{super_search_category_name} Jobs In {super_search_job_location}</h1>
    {/if}

    <h1>{super_search_category_name} Jobs</h1>

{if:else}

    <h1>Jobs In {super_search_job_location}</h1>

{/if}
| improve this answer | |
1

First, I would recommend using the excellent IfElse plugin to reduce load with advanced conditionals. To do this wrap your entire conditional in these tags:

{exp:ifelse parse="inward"}    
  code goes here
{/exp:ifelse}

Now onwards, please post the errors you are seeing as that will help us help you. Second, I would start off by simplifying your entire conditional to a single conditional and checking if that works. If it does then add the next part and repeat until you have found the error or have the entire thing working.

You might also try putting supersearch variables inside quotes:

{exp:ifelse parse="inward"}    
    {if '{super_search_keywords}' !=""}

        <h1>{super_search_keywords} Jobs</h1>

     {/if}

    {if '{super_search_category_name}' !=""}

        {if '{super_search_job_location}' !=""}
            <h1>{super_search_category_name} Jobs In {super_search_job_location}</h1>
        {/if}

        <h1>{super_search_category_name} Jobs</h1>

    {if:else}

        <h1>Jobs In {super_search_job_location}</h1>

    {/if}
{/exp:ifelse}
| improve this answer | |
  • Hi Sean thanks for taking the time to look at this I installed the suggested plugin tried just a simple[code] {exp:ifelse parse="inward"} {if {super_search_keywords} !=""} <h1>{super_search_keywords} Jobs ifelse</h1> {/if} {/exp:ifelse}[/code] Yet I get no title when the keyword isn't empty so I'm not sure if I can do this with super search – Anthony Ifon Nov 15 '13 at 13:55
1

Thanks Robson Sobral you set me on the right track the following fixes the conditionals

{if "{super_search_keywords}" !=""}
    <h1>{super_search_keywords} Jobs {if "{super_search_job_location}" !=""}
         In {super_search_job_location}
    {/if}</h1>

{if:elseif "{super_search_category}" !=""}
 <h1>{super_search_category} Jobs {if "{super_search_job_location}" !=""}
         In {super_search_job_location}
    {/if}</h1>


{if:else}
    <h1>Jobs In {super_search_job_location}</h1>
{/if}

I have one more thing which maybe should ask in a new question the {super_search_category} can only pull back the category ID is there anyway to convert this id to the name

| improve this answer | |

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.