This page shows the use of the url and asset convenience Ypage functions.
(shortcuts for the mkUrl and mkAssetUrl Webapp methods)
| ypage source | resulting string |
|---|---|
| First some normal urls | |
| url("") | /test/ |
| url("/") | /test// (note that the slash should not be used) |
| url("foo.html") | /test/foo.html |
| url("sub/foo.html") | /test/sub/foo.html |
| url("snoop.sn","arg") | /test/snoop.sn?arg |
| url("snoop.sn",params={"q1":"test", "q2":"42"}) | /test/snoop.sn?q1=test&q2=42 |
| url("snoop.sn","arg", [("q","test"),("q","42")]) | /test/snoop.sn?arg&q=test&q=42 |
| asset("sub/foo.jpg") | /test/img/sub/foo.jpg |
| Now some tricky urls that require escaping (click the hyperlinks to verify the result) | |
| url("snoop.sn/foo with " quote and spaces.html") | /test/snoop.sn/foo with " quote and spaces.html |
| url("snoop.sn/foo++==.html") | /test/snoop.sn/foo++==.html |
| url("snoop.sn/foo?q1=42&q2=43") | /test/snoop.sn/foo?q1=42&q2=43 |
| url("snoop.sn","arg with " quote and spaces and +=") | /test/snoop.sn?arg+with+%22+quote+and+spaces+and+%2B%3D |
| url("snoop.sn","arg with&thing=equals and/slash") | /test/snoop.sn?arg+with%26thing%3Dequals+and%2Fslash |
| url("snoop.sn",params={'quote"name':'quote"value'}) | /test/snoop.sn?quote%22name=quote%22value |
| url("snoop.sn",params={"q1":"test & +=","q2 & q3":"42&also=43"}) | /test/snoop.sn?q=test+%26+%2B%3D%2F&q2+%26+q3=42%26also%3D43 |
| url("snoop.sn","strange / arg",{"q1":"test & +=","q2 & q3":"42 and/or 43"}) | /test/snoop.sn?strange+%2F+arg&q1=test+%26+%2B%3D%2F&q2+%26+q3=42+and%2For+43 |
| asset('sub/foo with " quote and spaces and?ab=++blah.jpg') | /test/img/sub/foo with " quote and spaces and?ab=++blah.jpg |
| With and without escaping | |
| url("snoop.sn/with " quote and <>.html") | /test/snoop.sn/with " quote and <>.html (with escaping) |
| url("snoop.sn/with " quote and <>.html", htmlescape=False) | /test/snoop.sn/with " quote and <>.html (without escaping; invalid html) |
| asset('sub/with " quote and <> and?ab=++blah.jpg') | /test/img/sub/with " quote and <> and?ab=++blah.jpg (with escaping) |
| asset('sub/with " quote and <> and?ab=++blah.jpg',htmlescape=False) | /test/img/sub/with " quote and <> and?ab=++blah.jpg (without escaping; invalid html) |