FAQ
Hello,

I'm trying to use html/template correctly and it seems there is some logic
I haven't quite understood:

error html/template:index:9: on range loop re-entry: {{range}} branches end
in different contexts: {stateJS delimNone urlPartNone jsCtxRegexp attrNone
elementScript <nil>}, {stateJSRegexp delimNone urlPartNone jsCtxRegexp
attrNone elementScript <nil>}

My template fragment looks like this:

{{range .expiries}}
<option>{{.Name }}</option>
{{end }}

Removing the <option>, </option> element from the inner loop fixes the
issue. My understanding was that I could use that kind of feature (ie
nested html in a range construct).

Help ?!
Thanks for your time
--
Pierre.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Nigel Tao at Jun 24, 2013 at 7:32 am
    CC'ing Mike Samuel.

    On Mon, Jun 24, 2013 at 8:09 AM, wrote:
    I'm trying to use html/template correctly and it seems there is some logic I
    haven't quite understood:

    error html/template:index:9: on range loop re-entry: {{range}} branches end
    in different contexts: {stateJS delimNone urlPartNone jsCtxRegexp attrNone
    elementScript <nil>}, {stateJSRegexp delimNone urlPartNone jsCtxRegexp
    attrNone elementScript <nil>}

    My template fragment looks like this:

    {{range .expiries}}
    <option>{{.Name }}</option>
    {{end }}

    Removing the <option>, </option> element from the inner loop fixes the
    issue. My understanding was that I could use that kind of feature (ie nested
    html in a range construct).
    Can you show a bit more of your template around that {{range}}?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Octplane at Jun 24, 2013 at 7:35 am
    Hello :)
    On Monday, June 24, 2013 9:26:17 AM UTC+2, Nigel Tao wrote:

    CC'ing Mike Samuel.


    Can you show a bit more of your template around that {{range}}?


    After looking very closely to my template (and one good night after), I
    found out that the original template was:

    <script>
    <form class='form-inline' id='gluu_form' method='POST' action='/'>
             <button class='button btn btn-primary' type='submit' />
             <i class='icon-file icon-white'>Gluu</i>

             <span>Expiration <label class='checkbox'>
                     <input id='never_expire'> Never</input></label>
             <select id='expiry_delay' class='span3' name='expiry_delay'>
                     {{range .expiries}}
           <option {{.Attributes}} >{{.Name }}</option>
                     {{end }}
             </select>

    </form>
    </script>


    Can you spot (as now I do) the extra script element surrounding the whole
    template ? Now, I can, and once removed, the templates compiles and run
    beautifully. Mind you, the error message was not that explicit (the elementScript
    should have worried me though)...

    Thank you for having heard my babbling. Next time, I'll explain the issue
    to my rubber duck.

    Happy Go'ing
    --
    Pierre.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Mike Samuel at Jun 24, 2013 at 4:40 pm
    Yeah.

    I'm not trying to justify the inscrutability of the error message, but
    that error message happens because it starts in JS as indicated by
    "{stateJS" and then sees

        <option>{{.Name }}</option>

    which could be a sequence of valid but nonsensical JS tokens as in the
    explicitly parenthesized

         ((1 < option) > "name") < /option>/

    and ends inside a regular expression as indicated by "{stateJSRegexp"
    because only one slash has been seen.

    We could recognize this particular error and mention that there might
    be a stray `<script>` or unclosed `onclick="...` earlier in the
    template.



    2013/6/24 <octplane@gmail.com>:
    Hello :)
    On Monday, June 24, 2013 9:26:17 AM UTC+2, Nigel Tao wrote:

    CC'ing Mike Samuel.



    Can you show a bit more of your template around that {{range}}?


    After looking very closely to my template (and one good night after), I
    found out that the original template was:

    <script>
    <form class='form-inline' id='gluu_form' method='POST' action='/'>
    <button class='button btn btn-primary' type='submit' />
    <i class='icon-file icon-white'>Gluu</i>

    <span>Expiration <label class='checkbox'>
    <input id='never_expire'> Never</input></label>
    <select id='expiry_delay' class='span3' name='expiry_delay'>
    {{range .expiries}}
    <option {{.Attributes}} >{{.Name }}</option>
    {{end }}
    </select>

    </form>
    </script>


    Can you spot (as now I do) the extra script element surrounding the whole
    template ? Now, I can, and once removed, the templates compiles and run
    beautifully. Mind you, the error message was not that explicit (the
    elementScript should have worried me though)...

    Thank you for having heard my babbling. Next time, I'll explain the issue to
    my rubber duck.

    Happy Go'ing
    --
    Pierre.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ibrahim M. Ghazal at Jun 25, 2013 at 4:58 am

    On Mon, Jun 24, 2013 at 7:40 PM, Mike Samuel wrote:
    Yeah.

    I'm not trying to justify the inscrutability of the error message, but
    that error message happens because it starts in JS as indicated by
    "{stateJS" and then sees

    <option>{{.Name }}</option>

    which could be a sequence of valid but nonsensical JS tokens as in the
    explicitly parenthesized

    ((1 < option) > "name") < /option>/

    and ends inside a regular expression as indicated by "{stateJSRegexp"
    because only one slash has been seen.
    This is brilliant. I knew html/template uses context to safely escape
    strings in html, but I didn't know it went as far as parsing
    JavaScript. Thank you for your great work.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 24, '13 at 4:44a
activeJun 25, '13 at 4:58a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase