Added the code at line 1 on the index page and before login the cart detail is hidden and after login the quickcart detail is displayed ok but as soon as logout is clicked the same error returns. See attachment.
If this problem can be resolved does the solution need to be added manually to each page.