Forum OpenACS Development: Re: dotLRN development tips, tutoriasl quick guides????

Collapse
Posted by Nima Mazloumi on
<h3>Dynamic Portlets</h3>

WARNING: YOU NEED TO KNOW THAT THE BELOW SOLUTION CAN CAUSE GREAT DAMAGE. THIS IS ONLY A QUICK SOLUTION AND YOU NEED TO DO A LOT MORE TO ENSURE THAT NOONE EXCEPT THE SYSTEM ADMIN CAN MAKE USE OF THIS EXTENDED FUNCTIONALITY.

  1. You can take the static-portlet package for this purpose. My suggestion is though to create a new package called dynamic-portlet where only a system admin can create portlets.
  2. Now edit the following page static-portlet/www/static-portlet.tcl and add the following two lines at the end of the page:
    eval [template::adp_compile -string $content]
    set content ${__adp_output}
  3. Now when you add new content to the portlet you can use all ADP template tags and also tcl code. Just make sure that you don't use the %-tag for the tcl. Instead use the tcl-tag. A sample list for instance could look like this, where you first do your tcl stuff and then use them in your html page.
    < tcl >
    template::list::create -name persons -multirow persons -key item_id -elements {
                first_names {
                    label "First Names"
                }
                last_name {
                    label "Last Name"
                }
            }
    
        db_multirow persons select_persons {
            select * from persons where last_name = 'Mueller'
        }
    < /tcl >
    < listtemplate name="persons" >< /listtemplate >


    Here another example with forms:
    < tcl >
    ad_form -name my_form -form {
            {first_names:text(text) {value ""} {label "First Names"} {html { size 55 }} }
            {last_name:text(text) {value ""} {label "Lastname"} {html { size 55 }} }

    } -validate { {first_names {[string length $first_names] >= 2} "First names must be more than 2 characters" } } -new_data { #do something here } -edit_data { #do something here } -after_submit { ad_returnredirect "." ad_script_abort } < / tcl > < formtemplate id="my_form" >< / formtemplate >



    Make sure you remove the above spaces on the tcl, listtemplate and formtemplate tags to make the examples work.