1

If I have a block of #raw that has javascript inside it and sometimes I need to access some python variables (the $foo in example case) from that javascript.

#raw

 <script type="text/javascript" charset="utf-8" >
    if ( 
        #end raw
          $foo
        #raw
        and $('#manuf').val() )  {
          getNextFreeProdCode(
            $('#category option:selected').val(),
            $('#subCat option:selected').val(),
            $('#manuf option:selected').val()
           );
        }
  </script>
#end raw

first of all, that looks ugly and not so readable code. I would like to have if operator in single line.

But is there:

  • a way to introduce those variables with some placeholders like %s in python strings?
  • Or some way to tell #raw what that block is and give those variables for it as an argument? Like:

    #raw($foo, $bar) . if ( $(#manuf).val() or $foo ) { fooBar($bar); . . . } #end raw

    just like in #def define block allows arguments like function call.

Actually I would like the second way more, and maybe it shouldn't be called #raw but it could be raw-content-specific, like #ecmascript() ... #end ecmascript?

Maybe there is already a solution for this?

Juha

Juha Tuomala
  • 111
  • 11

1 Answers1

1

Well, it is either raw or not raw, i.e. parsed. If you want parsed variables inside a block the block cannot be raw. You have to escape dollar signs inside a parsed block.

phd
  • 82,685
  • 13
  • 120
  • 165