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.

Conditional test for text string at beginning of an entry

August 23, 2012 8:01am

Subscribe [2]
  • #1 / Aug 23, 2012 8:01am

    Rick Lecoat

    128 posts

    Hi;

    is it possible to use a conditional to test whether a the contents of channel entry field begins with a particular text string? For example, I have a channel field that holds a URL. I’d like to check whether that URL has been entered with http:// at the beginning, or whether it just starts with www (in which case I’ll use the conditional to insert the http:// dynamically).

    Is this possible?

  • #2 / Aug 23, 2012 11:08am

    Boyink!

    5011 posts

    I have seen a URL field type that might prevent the need for the conditional.  Otherwise there are several string-management type plugins that might work.

  • #3 / Aug 23, 2012 3:06pm

    Dan Decker

    7338 posts

    Hi Rick,

    Have a look at PVL Check If. It’s one of the many string-related plugins that Mike was talking about.

    Cheers,

  • #4 / Aug 23, 2012 4:42pm

    Rick Lecoat

    128 posts

    Cheers Mike. Just wanted to double check that I wasn’t overlooking some native functionality before I went off looking for a plugin solution.

    Dan: Thanks for the suggestion. Looks great at first glance, although I’m just trying to see how the syntax would work for checking the above example. I guess something like:

    {exp:pvl_checkif value={url_field} contains=“http://”}
    {url_field}
    {else}
    http://{url_field}
    {/exp:pvl:checkif}

    nested inside a channel:entries tag?

  • #5 / Aug 24, 2012 3:51pm

    Dan Decker

    7338 posts

    Hey Rick,

    That’s my reading of it, yup! Is there anything else I can assist you with?

    Cheers,

  • #6 / Aug 24, 2012 4:23pm

    Rick Lecoat

    128 posts

    No, I think that’s it Dan, thanks. One thing did occur to me though, which is that the *contains* syntax for PVL CheckIf will work in the context of the URL example I outlined above (where there is only ever going to be one instance of http:// in the string), but could fail if I wanted to check for a particular text string at the start of a more generalised block of text (where the key string might conceivably exist further into the text rather than specifically at the start).

  • #7 / Aug 27, 2012 12:57pm

    Kevin Smith

    4784 posts

    That’s certainly a consideration, Rick. I would think that it’s a better course of action here to use a fieldtype that checks for a URL while submitting the entry instead. Something like JCO URL.

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

ExpressionEngine News!

#eecms, #events, #releases