Note that there are some explanatory texts on larger screens.

plurals
  1. POweb2py server-side comments
    primarykey
    data
    text
    <p>In a web2py view, how do I comment out server-side code? In ASP.NET, I can surround any HTML or code tags with &lt;%-- and --%> and that block will not be compiled or sent to the client. Velocity does the same thing with #* and *#. Is there an equivalent in web2py?</p> <p><strong>ASP.NET</strong></p> <pre><code>&lt;div&gt; &lt;p&gt;&lt;%=foo.bar%&gt;&lt;/p&gt; &lt;%-- don't print twice! &lt;p&gt;&lt;%=foo.bar%&gt;&lt;/p&gt; --%&gt; &lt;/div&gt; </code></pre> <p><strong>web2py</strong></p> <pre><code>&lt;div&gt; &lt;p&gt;{{=foo.bar}}&lt;/p&gt; ??? don't print twice! &lt;p&gt;{{=foo.bar}}&lt;/p&gt; ??? &lt;/div&gt; </code></pre> <p><em>EDIT: Fixed web2py code tags.</em></p> <hr/> <h2>Problem with block comments</h2> <p>An exception is thrown if {{'''...'''}} and {{"""..."""}} are used with code blocks inside. A non-ideal workaround that leaves the code mostly unchanged is removing the double-braces from the commented-out code blocks.</p> <p><strong>HTML</strong></p> <pre><code>{{'''{{somefunction(42)}}'''}} </code></pre> <p><strong>Error</strong></p> <pre><code>Traceback (most recent call last): File "gluon/restricted.py", line 176, in restricted File "gluon/restricted.py", line 163, in compile2 File "C:\development\web2py\applications\SpaceCorps/views\default/index.html", line 74 '''{{somefunction(42)\nresponse.write("'''}}\r\n\t\t\r\n\t&lt;/div&gt;\r\n&lt;/div&gt;\n\t&lt;/body&gt;\n&lt;/html&gt;\n",escape=False) ^ SyntaxError: invalid syntax </code></pre> <p><strong>Generated View code</strong></p> <pre><code>'''{{somefunction(42)\nresponse.write("'''}}\r\n\t\t\r\n\t&lt;/div&gt;\r\n&lt;/div&gt;\n\t&lt;/body&gt;\n&lt;/html&gt;\n",escape=False) </code></pre> <h2>Problem with single-line comment</h2> <p>{{#}} successfully comments, but also doesn't quite work as expected. This may be more difficult to fix, however, and should be easy to work around. The following HTML will render two end brackets to the final HTML, while I think it should render nothing.</p> <p><strong>HTML</strong></p> <pre><code>{{#{{somefunction(42)}}}} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload