locked
AddSymbol and [!if MYSMBOL] RRS feed

  • Question

  • I have tried adding a symbol at runtime based on a condition. If the condition is not met, I don't add the symbol. However it appears that when parsing template files [!if MYSYMBOL] evaluates to true even if I don't add the symbol. So I tried calling AddSymbol("MYSYMBOL", "false"). But still, [!if MYSYMBOL] appears to evealute to true.

    I say "appears" because I have not figured out how to debug the parsing of my templates.

    I even tried going to the default.htm and in the "SYMBOL tag" section adding an entry with no "TYPE" member (otherwise I get an error loading the script if I set the type to something like "TYPE=checkbox" since I don't want to show a UI element on the page).

    <SYMBOL NAME='MYSYMBOL' value=false></SYMBOL>

    Why would [!if MAKINGTHISUP] evaluate to true if I have not added "MAKINGTHISUP" as a symbol or if I added it and set the value to "false"?


    R.D. Holland
    Tuesday, January 10, 2012 5:14 PM

All replies

  • Hi RD,

    What type of your project?

    Which language do you use? C#, VB or others?

    If you can provide a reproduce steps or sample code to reproduce this project,  you will be able to get quicker and better responses.

    Thank you for your understanding!

     

    Best regards,

    Lucy

     


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, January 12, 2012 8:15 AM
  • It is a VC project generated using the custom wizard wizard. I just created another one. I went to new project/general and selected custom wizard to get the stock project. Then I opened "Sample.txt" and added this:

    [!if JUSTATEST]

    This is just a test.

    [!endif]

     

    I then built the project and copied the .ico, .vsdir and .vsz files to the Visual Studio 10.0\VC\vcprojects dir. Then I started VS and used that new wizard to generate a project. When I open sample.txt I see:

     

    "This is just a test".

    So without even adding the symbol, the [!if] apparently evals to true. I'll attach a zip with this simple project. Well I'll try to add a zip. I see a button to insert an image and other buttons but no upload button. Perhaps after I submit I can do so.


    R.D. Holland
    Thursday, January 12, 2012 3:56 PM
  • Sorry. The button/control to allow me to upload sample (zip file) must be so obvious I am completely overlooking it! I hope the steps I gave are sufficient. I am posting this from with Visual Studio 10. VS has a lot of problems displaying the forum page (doesn't fit and maximizing VS or dragging it across my second monitor to make it even bigger simply causes a lot of "gray space" to appear on the left side, which I can see is clipped even when the app is maximized. Perhaps the button is clipped like the "Home" link and other stuff on the left edge of the window.


    R.D. Holland
    Thursday, January 12, 2012 4:08 PM
  • Hi RD,

    According to your description.

    [!if JUSTATEST]

    This is just a test.

    [!endif]

    If the JUSTATEST is true , then the “!if JUSTATEST” is false. Similarly, if the JUSTATEST is false then the “!if JUSTATEST” is true, that it will print the “This is just a test.”

    So please try to set the JUSTATEST to be true, see whether it can solve this issue.

    >> It is a VC project generated using the custom wizard wizard.

    As you use the custom wizard to create your vc project, so I cannot reproduce this issue without your custom wizard.

     

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Friday, January 13, 2012 8:55 AM
  • Lucy!

    [!directiveparams] is the syntax according to the MSDN for template directives.

    ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vcide/html/b6204153-813a-423c-b044-e39c352cc5af.htm

    If one wants to "negate" the value of a variable, one uses the "!" char with the directive param.

    [!if !JUSTATEST]

    // emitted comment

    [!else]

    That is, I am using the template directives properly as indicated by the MSDN link above. Note even an "else" needs "!" as does every directive.

    As for my custom wizard, you too can create one using the steps I outlined since I could not find a way to upload a zip file with the sample I generated (to which I added no code other than what I indicated in the sample.txt template the custom wizard wizard generated). Just a couple of clicks is all one needs to get the base project. Then simply add the directive to the sample.txt file and run the wizard generated by the wizard. Pretty simple really.

    That is, this has nothing to do with any changes I made to my VC wizard. One can duplicate the issue easily right-out-of-the-box.


    R.D. Holland
    Tuesday, January 17, 2012 9:07 PM
  • I believe I have solved this mystery. Assume I don't add the symbol "MYSYMBOL".

    In the default.htm file I can do this:

    var val = window.external.FindSymbol("MYSYMBOL");

         if( val == true )

         { // code block for true condition

          }

    At runtime the debugger shows me the definition of "val" is "undefined". The result of if( val == true ) is false (code block is not entered, no exception is thrown).

    However in the sample.txt template file the below condition evaluates to true.

    [!if MYSYMBOL]

    You selected MYSYMBOL

    [!endif]

    Hence there is a disconnect between the "value" of an undefined symbol in the default.htm file and a template file. I expected the above to evaluate to false since no symbol was added to the symbol table. That is, the symbol is undefined and I expect the test to fail as it does in the default.htm source code.

    What I found I have to do is always add  MYSYMBOL to the symbol table. If I do so set it to false, the code in the default.htm and the template directive both evaluate to "false" conditions.

    It appears there is a subtle difference in the semantics of the "if" statement and "if" directive. So I now always add a symbol and set its value to true or false.


    R.D. Holland
    Tuesday, January 24, 2012 2:58 PM