Template bad references

In templates there are some incorrect access to context variables. This pull request attempts to fix it.