0

I'm using DevDemon Forms, on two of my pages, which requires that jquery be included in the the document head. On other pages however, I want to include jquery in the footer.

So i thought I would post this in the header:

{if "{segment_2}" == "skjema" OR "{segment_2}" == "nyhetsbrev"}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="{site_url}js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
{/if}

Then post this in the footer:

{if "{segment_2}" != "skjema" OR "{segment_2}" != "nyhetsbrev"}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="{site_url}js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
{/if}

The first part works fine, as jquery is now only included in the header on page "skjema" and "nyhetsbrev".

The second part does not work, as it includes jquery no matter what, which means I'm including jquery twice on pages using Forms.

4

TL;DR: Use AND in your second conditional.

Actually, it is working as expected. In the first conditional, you're saying if x is a or x is b, which will return true if x is a or b. The second conditional says if x is not a or x is not b, which will return true if x is a or b, as x cannot be both. Simple logic.

I take it you want the second conditional to be the opposite of the first one, so: if x is not a or b, which is the same as if x is not a and x is not b:

{if segment_2 != "skjema" AND segment_2 != "nyhetsbrev"}

Also note that I've removed the quotes and curly braces around the segment vars, which is best practice.

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.