Hi, it’s writtten that “return”, without return value, within a template exists it. I try to do that within render-link.html with this:
{{- if $isRemote -}}
{{ if not .Destination}}{{return}}{{end}}
{{- else }}
but it’s ignored, I get the homepage (for the given language). I would like links with no destination (meaning, with destination or translation to be added later) to not be processed as a link.
I don’t understand what you mean, but your example would not work, even in a partial:
{{- if $isRemote -}}
{{ if not .Destination}}{{return}}{{end}}
{{- else }}
Ref. the docs:
A partial that returns a value must contain only one return statement, placed at the end of the template.
Note that the return keyword is not a native Go template “thing”, this is Hugo doing template rewrites on the AST level, and that would not make sense/be worth it for all templates.
I have read about a “native Go template keyword”, but I’m not sure what’s the status of that keyword.
ah ok, I treated it as an “exit” statement but it really doesn’t work that way.
I’ll change the code’s logic. Unless there is another way to quit the render hook abruptly ?
Rob Pike has done many great things for that project, but he has been overly grumpy about accepting changes in “his” package. For many years there were obvious data races that he refused to fix because it meant rewriting the parser – he wanted to keep the original implementation because it was linked to from a popular presentation he did on parsers (it’s on YouTube).
I suspect the return keyword will happen an hour after Russ Cox decides that he needs/wants it.