Searching a keyword in a snippet to create an IF statement

I have an {if:} statement that I use in multiple snippets. I'm trying to figure out a way to search my snippet for a specific word, then have it trigger a nested {if:} statement that would change the wording in my original {if:} statement. I was thinking testregex could do this, but it seems that the wording has to be inside a form to work with testregex. Essentially, this is what I would want the snippets to look like.

Snippet #1: Your next assignment is lesson 1.01. It identifies the elements of a plot and defines a universal theme. You will use these concepts in multiple lessons going forward. Make sure you take very good notes.

Snippet #2: Here's what's coming up next. Lesson 1.01 identifies the elements of a plot and defines a universal theme. You will use these concepts in multiple lessons going forward. Make sure you take very good notes.

Original {if:} Statement: {if: Lesson # == "1.01"}Lesson 1.01 identifies the elements of a plot and defines a universal theme. You will use these concepts in multiple lessons going forward. Make sure you take very good notes.{endif}

New {if:} Statement: {if: Lesson # == "1.01"} {if: ?}It{else}Lesson 1.01{endif} identifies the elements of a plot and defines a universal theme. You will use these concepts in multiple lessons going forward. Make sure you take very good notes.{endif}

I can't figure out what I can place in the "?" position of the nested {if:} statement above that will search the rest of my snippet for a keyword without the keyword being in a form. For example, having it search for the word "lesson" in the previous sentence. Is this possible?

Hi Jennifer,

Are you trying to conditionally change the word "It" depending on what lesson is inserted?

If so, you could try something like the example below that changes the word inserted depending on how many lessons you plan to discuss.

{note}{formtext: name=lessoncount; cols=5; default=2}{endnote}
{if: lessoncount = 1} it{else}they{endif}

You could also try this:

{note}{formmenu: default=one; more than one; name=lessonname}{endnote}

{if: lessonname = "one"}it{else}they{endif}

Is that what you are trying to do?

To answer your question about searching a snippet for a keyword, I don't believe this is possible. Instead, I think using a formmenu or formfield might be a simpler option. Would that work?

Let me know if that helps and if you have any questions.

1 Like

Hi Dylan! It's more like trying to conditionally change the word "it" if the word "lesson" was previously used in the snippet. However, the word "lesson" is not in any form, it's just part of the snippet. I guess I would have to rework the snippet to make sure the keyword I'm focusing on is inside a formfield. Thank you Dylan!

1 Like