Include control specific data in layout.html header

11 views
Skip to first unread message

Jon Subscripted

unread,
Apr 1, 2020, 4:00:04 PM4/1/20
to web...@googlegroups.com
Hi everyone,
I'm trying to include view specific data in each view header (it is actually a GTM datalayer).

I thought the best way to do it was to define a global variable in db.py and to print a variable  {{=datalayer}}, the each controller will overwrite it with specific data.

It seems to be working for most of my views, except:
-index.html
-all user.html views (login/register/profile/change_password/etc.)

Any suggestions on how to make it work on index.html and user.html?
What am I doing wrong?
Thanks in advance, Jon.

Jon Subscripted

unread,
Apr 1, 2020, 4:09:20 PM4/1/20
to web...@googlegroups.com
Hi everyone,
I've just realized what I was doing wrong.

What happened is that I was not returning locals(), but a custom dict, which was not updated.

Right implementation:

def index():
    datalayer = get_datalayer('general','index')
    return locals()

Wrong implementation:

def index():
    datalayer = get_datalayer('general','index')
    return dict(message=T('Welcome to my app!'))


Thanks! Jon.

Reply all
Reply to author
Forward
0 new messages