with_args

14 views
Skip to first unread message

Alan M.

unread,
Dec 19, 2019, 5:03:43 AM12/19/19
to Zotonic users
Hello Zotonic team and users!
I have a few questions on with_args action.
I created fresh site from "blog" skeleton ang made the following template based on base.tpl:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test with_args action</title>
{% lib
"bootstrap/css/bootstrap.min.css"
"bootstrap/css/bootstrap-theme.min.css"
"css/jquery.loadmask.css"
"css/z-menu.css"
"css/project.css"
%}
</head>
<body>
{% with "Some message" as value %}
 {% wire type="click" id=#anchor action={with_args action={growl stay} arg={text value} } %}
 <div id="testlink"><a href="#" id={{#anchor}}>Growl with {{value}}</a></div>
 {% wire type="click" id=#anchor1 action={growl stay text=value}  %}
 <div id="testlink"><a href="#" id={{#anchor1}}>Growl with {{value}} directly</a></div>
{% endwith %}
{% for msg in ["First", "Second", "Third"] %}
 <div id="{{#div.msg}}">
 {% wire type="click" id=#anchor.msg action={with_args action={growl stay} arg={text msg}} %}
 <a href="#" id="{{#anchor.msg}}">Growl for {{msg}}</a>
 </div>
 <div id="{{#div1.msg}}">
 {% wire type="click" id=#anchor1.msg action={growl stay text=msg} %}
 <a href="#" id="{{#anchor1.msg}}">Growl for {{msg}} directly</a>
 </div>
{% endfor %}
{% lib
"js/apps/jquery-latest.min.js"
"js/apps/jquery-migrate-1.4.1.min.js"
"js/apps/jquery-ui-latest.min.js"
"js/modules/jquery.ui.touch-punch.min.js"
"bootstrap/js/bootstrap.min.js"
"js/modules/ubf.js"
"js/apps/zotonic-1.0.js"
"js/apps/z.widgetmanager.js"
"js/modules/ubf.js"
"js/modules/livevalidation-1.3.js"
"js/modules/z.inputoverlay.js"
"js/modules/z.dialog.js"
"js/modules/jquery.loadmask.js"
"js/z.superfish.js"
"js/modules/z.notice.js"
"js/qlobber.min.js"
"js/pubzub.js"
"js/modules/jquery.hotkeys.js"
"js/modules/z.adminwidget.js"
"js/modules/z.tooltip.js"
"js/modules/z.feedback.js"
"js/modules/z.formreplace.js"
"js/modules/z.datepicker.js"
"js/modules/z.menuedit.js"
"js/modules/z.cropcenter.js"
"js/modules/jquery.shorten.js"
"js/modules/jquery.timepicker.min.js"
"js/apps/admin-common.js"
"js/jquery.ui.nestedSortable.js"
"js/qlobber.min.js"
"js/pubzub.js"
%}
<script type="text/javascript">
$(function() { $.widgetManager(); });
</script>
{% script %}
</body>
</html>

and added dispatch rule:

{with_args,    ["with_args"],              controller_template,  [ {template, "with_args.tpl"} ]}

When I open http://mysite:8000/with_args and click on links wired to growl action, I see growls with text specified in variable, but when i click on links wired to with_args meta-action, I see empty growls. What did I do wrong?
My task is to offer a visitor possibility to set a session variable by selecting an option from a (dropdown or fixed) list. The list is generated in a {% for %} loop and each item has several actions wired to it: set the variable, change previous value shown on this page, trigger changing the variable on all pages within current session, and hide the list if it is a dropdown.
Also, I have some "speculative" question - should I at all use with_args, or wiring the actions directly to anchors is the preferred way?

Alan M.

unread,
Dec 21, 2019, 11:41:11 AM12/21/19
to Zotonic users
Kept digging after posting the question and, having looked into modules/mod_base/actions/action_base_with_args.erl, found that the following trick works:
{% with "Some message" as value %}
{% wire type="click" id=#anchor action={with_args action={growl stay} arg={text message} message=value } %}

<div id="testlink"><a href="#" id={{#anchor}}>Growl with {{value}}</a></div>
{% endwith %}
However, I am not sure if this is a correct solution, or an "undocumented feature" which is not to be relied upon.
Reply all
Reply to author
Forward
0 new messages