ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Escaping quotes in conditionals

January 28, 2008 5:32pm

Subscribe [2]
  • #1 / Jan 28, 2008 5:32pm

    scottdevries

    103 posts

    How do I escape quotation marks in conditional statements? For example:

    {if summary=""text""}
    Do something
    {/if}
  • #2 / Jan 28, 2008 5:50pm

    Mark Bowen

    12637 posts

    Don’t know if this will work at all but is the usual form for escaping characters :

    {if summary == "\"text\""}
    Do something
    {/if}

    As I said before not too sure if it works in that way though. Also why are you testing for a one word existence with quotes in a field? Would it not be easier to just have the word test in the field and then test for that and add in the quotes to the rendered page afterwards?

    Best wishes,

    Mark

  • #3 / Jan 28, 2008 5:56pm

    Lisa Wess

    20502 posts

    I have to agree, you shouldn’t need to be escaping quotes in conditionals. What is your actual goal here?

  • #4 / Jan 28, 2008 5:57pm

    Mark Bowen

    12637 posts

    Actually scrap that. Just tried it and it didn’t work.

    Try this instead, it may work for you :

    {if body == ""test""}
    Do something…
    {/if}

    Might be best if you get an answer from support on this one though as it is a little odd to be doing.

    Best wishes,

    Mark

  • #5 / Jan 28, 2008 5:59pm

    Mark Bowen

    12637 posts

    Again to re-iterate what both myself and Lisa have said it might be worth you letting us know exactly why you are doing this though as there is probably a better way to accomplish what you need.

    Best wishes,

    Mark

  • #6 / Jan 29, 2008 11:55am

    scottdevries

    103 posts

    I’ve got some custom fields that have inch measurements in them, and I want to test for some certain sizes. I would go through the custom fields and delete the “, but I’ve got over 500 entries to do that for.

    I’ll try your suggestion, Mark.

  • #7 / Jan 29, 2008 11:57am

    Mark Bowen

    12637 posts

    Hiya,

    Hopefully it should work in that way but I would say that if the only thing being store in the field is the measurement then it would be best to add in the inches mark afterwards in the template. If it isn’t the only thing in the field then you could always use a css class or even a plugin to add the marks back in again.

    Best wishes,

    Mark

  • #8 / Jan 29, 2008 12:09pm

    Robin Sowell

    13255 posts

    Hm- untested, but does it work with single quotes:

    {if summary == '"text'}
    Do something
    {/if}

    Could also go with php if you get into a bind on it.

  • #9 / Jan 29, 2008 12:20pm

    Mark Bowen

    12637 posts

    Hm- untested, but does it work with single quotes:

    {if summary == '"text'}
    Do something
    {/if}

    Could also go with php if you get into a bind on it.

    Unfortunately I just tried this and I couldn’t get it to work. I think the only ways are to use ascii encoding or to put the inches marker in afterwards in the template or perhaps use PHP as you mentioned.

    Best wishes,

    Mark

  • #10 / Jan 29, 2008 12:32pm

    scottdevries

    103 posts

    Hmm, can’t get to work, but for all the wrong reasons. I’m getting a “Compilation failed: regular expression too large” error, probably because I’m executing that query inside 4 others. I’ll have to do it another way. Thanks for the help, I think the way that Robin said should work under normal circumstances.

  • #11 / Jan 29, 2008 12:36pm

    Robin Sowell

    13255 posts

    Yea- it’s entirely possible something goes hinky that way.  I hadn’t tried it.  Personally- I’d go php parsed on output.  But- if you want me to poke around a bit- let me know what formating the field that holds the inches is set to.  I could run some tests, just see what’s going on.  Hm- or format it light xhtml- encode the double quotes- then match those?  Would that work?  If you’re doing it via queries, no text formatting going on.  With weblog tags- you’ll get whatever formating it’s set to.  That could be in play, if there’s a lot of nesting.

  • #12 / Jan 29, 2008 12:37pm

    Mark Bowen

    12637 posts

    Hiya,

    I tested out using :

    {if summary == '"text'}
    Do something
    {/if}

    and I am pretty sure that unfortunately it won’t work. Admittedly it was a very very quick test but it was done in a template without any other tags or anything in it so pretty much the bare bones basics I’m afraid.

    PHP would probably do what you need though. Is there no possibility of taking out the markers in the fields though or is their other data in the field too?

    Best wishes,

    Mark

  • #13 / Jan 29, 2008 12:40pm

    Mark Bowen

    12637 posts

    One other thing you could do if the field does just hold the marker and the number is use the Find & Replace utility in the CP to change all to ".

    Don’t know if that is of any use to you but just a thought?

    Best wishes,

    Mark

  • #14 / Jan 29, 2008 12:54pm

    scottdevries

    103 posts

    Ooh, I’ve never seen the find and replace tool, could come in handy, thanks!

    I found another custom field that I can sort by, so the escaping quotes problem has been nullified. If I need to do it in the future, I think I’ll probably encode the double quotes, like Mark has suggested.

  • #15 / Jan 29, 2008 12:56pm

    Mark Bowen

    12637 posts

    Just be careful using the Find & Replace utility. It is very very powerful but there is of course no undo button so if you make a boo boo it is permanent.

    Glad you have something working now though. 😊

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases