Can I pass an arg to a wired script

13 views
Skip to first unread message

Jeff Bell

unread,
Jan 25, 2012, 4:20:05 PM1/25/12
to Zotonic users
I have a template that renders a custom modal form that looks like this.

_modal.tpl

{% wire id=id_div   action={update target=target_div template=div_template }
 action={script
         script="$('#modal').modal({onOpen: function (dialog) {
                dialog.overlay.fadeIn('slow', function () {
                       dialog.data.hide();
                       dialog.container.fadeIn('slow', function () {
                          dialog.data.slideDown('slow');
                       });
                });
                },
                dataCss: {
                        margin: 10
                },
                containerCss:{
                        height: 500,
                        width:  550
                },
                overlayClose:true
            });
           "
        }
%}

I call it like this

{% include "scripts/_uptime_base.tpl" id_div="info" target_div="modal" div_template="info.tpl" id=id %}
{% include "scripts/_uptime_base.tpl" id_div="contact" target_div="modal" div_template="_contact_form.tpl" %}

What I'd like to do, is pass variables to the script text, such as height and width.  For instance, 

{% include "scripts/_uptime_base.tpl" id_div="info" target_div="modal" div_template="info.tpl"  div_height="500" div_width="550" %}

and change my template to look "something" like this ...
...
                containerCss:{
                        height: div_height,
                        width:  div_width
                },

...

Any suggestions or comments on how to do this or should I try to make this a scomp?

Cheers

Jeff




Arjan Scherpenisse

unread,
Jan 25, 2012, 4:27:09 PM1/25/12
to zotoni...@googlegroups.com
My guess would be not to make it a scomp, but an action, for instance
called "modaldialog".

It would have arguments like width and height.

Look at the actions/ folder in mod_base to see plenty of examples of
actions. One suggestion: put as much as possible script in an external
javascript file so your action only needs to generate a tiny bit of
javascript. This saves you from intermingling javascript and erlang code
too much.

Good luck!

Arjan

Jeff Bell

unread,
Jan 25, 2012, 5:20:39 PM1/25/12
to zotoni...@googlegroups.com
Sweet, I was able to get it working by using action_base_growl as an example.  

Muchas gracias!

Jeff
Reply all
Reply to author
Forward
0 new messages