Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] Test string against expression?

Expand Messages
  • Rick Miller
    Hi All, Please forgive my ignorance for I am a novice in the area of templating engines and cheetah. That said, I want to compare a string in a placeholder
    Message 1 of 4 , Sep 17, 2012
    • 0 Attachment
      Hi All,

      Please forgive my ignorance for I am a novice in the area of
      templating engines and cheetah. That said, I want to compare a string
      in a placeholder against a regular expression (btw, this is in
      Cobbler...not sure if it makes a real difference or not). The concept
      is as follows:

      #if $getVar('name') == '*string*'
      #set foo = "bar"
      #else
      #set bar = "foo"
      #end if

      What is the best approach to accomplishing this?

      ------------------------------------------------------------------------------
      Live Security Virtual Conference
      Exclusive live event will cover all the ways today's security and
      threat landscape has changed and how IT managers can respond. Discussions
      will include endpoint security, mobile security and the latest in malware
      threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Buck Golemon
      Cheetah is a superset of python (kindof). Get your logic working in python, then port it to cheetah. You want re.match, from the standard python library:
      Message 2 of 4 , Sep 17, 2012
      • 0 Attachment
        Cheetah is a superset of python (kindof).
        Get your logic working in python, then port it to cheetah.
        You want re.match, from the standard python library:

        In your particular example below however, regular expressions are overkill, just use the string `in` operator:

        #if 'string' in $getVar('name')
           #set foo = "bar"
        #else
           #set bar = "foo"
        #end if

        That's basic python. You should take a couple hours and run through the official tutorial.
        At *least* skim the parts on string processing.
        http://docs.python.org/tutorial/ 

        On Mon, Sep 17, 2012 at 10:46 AM, Rick Miller <vmiller@...> wrote:
        Hi All,

        Please forgive my ignorance for I am a novice in the area of
        templating engines and cheetah.  That said, I want to compare a string
        in a placeholder against a regular expression (btw, this is in
        Cobbler...not sure if it makes a real difference or not).  The concept
        is as follows:

        #if $getVar('name') == '*string*'
           #set foo = "bar"
        #else
           #set bar = "foo"
        #end if

        What is the best approach to accomplishing this?

        ------------------------------------------------------------------------------
        Live Security Virtual Conference
        Exclusive live event will cover all the ways today's security and
        threat landscape has changed and how IT managers can respond. Discussions
        will include endpoint security, mobile security and the latest in malware
        threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss

      • Rick Miller
        ... Thanks, Buck! I ll check out that tutorial! ... Live Security Virtual Conference Exclusive live event will cover all the ways today s security and threat
        Message 3 of 4 , Sep 17, 2012
        • 0 Attachment
          On Mon, Sep 17, 2012 at 2:04 PM, Buck Golemon <buck@...> wrote:
          > Cheetah is a superset of python (kindof).
          > Get your logic working in python, then port it to cheetah.
          > You want re.match, from the standard python library:
          >
          > http://docs.python.org/library/re.html#re.RegexObject.match
          >
          >
          > In your particular example below however, regular expressions are overkill,
          > just use the string `in` operator:
          >
          > #if 'string' in $getVar('name')
          > #set foo = "bar"
          > #else
          > #set bar = "foo"
          > #end if
          >
          > That's basic python. You should take a couple hours and run through the
          > official tutorial.
          > At *least* skim the parts on string processing.
          > http://docs.python.org/tutorial/

          Thanks, Buck! I'll check out that tutorial!

          ------------------------------------------------------------------------------
          Live Security Virtual Conference
          Exclusive live event will cover all the ways today's security and
          threat landscape has changed and how IT managers can respond. Discussions
          will include endpoint security, mobile security and the latest in malware
          threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Buck Golemon
          If you re coming from Perl, the first thing you should know about python is that regular expressions are generally the Wrong Way to do it. Nearly everywhere
          Message 4 of 4 , Sep 17, 2012
          • 0 Attachment
            If you're coming from Perl, the first thing you should know about python is that regular expressions are generally the Wrong Way to do it.
            Nearly everywhere you'd use a regex in perl, you use a string method in python. It's more explicit and faster (especially since regex in python is not super optimized like perl).

            On Mon, Sep 17, 2012 at 11:22 AM, Rick Miller <vmiller@...> wrote:
            On Mon, Sep 17, 2012 at 2:04 PM, Buck Golemon <buck@...> wrote:
            > Cheetah is a superset of python (kindof).
            > Get your logic working in python, then port it to cheetah.
            > You want re.match, from the standard python library:
            >
            > http://docs.python.org/library/re.html#re.RegexObject.match
            >
            >
            > In your particular example below however, regular expressions are overkill,
            > just use the string `in` operator:
            >
            > #if 'string' in $getVar('name')
            >    #set foo = "bar"
            > #else
            >    #set bar = "foo"
            > #end if
            >
            > That's basic python. You should take a couple hours and run through the
            > official tutorial.
            > At *least* skim the parts on string processing.
            > http://docs.python.org/tutorial/

            Thanks, Buck!  I'll check out that tutorial!

          Your message has been successfully submitted and would be delivered to recipients shortly.