Forum OpenACS Q&A: globalizing ecommerce toolbar, howto know if "in" package instance?

I want to move more of the templating "includes" from ecommerce to the default-master, so there can be greater continuity in presentation format (before page content). For example, include parts of the ecommerce toolbar, such as ec_search_widget. And equally important, do not present some other stuff (check shopping cart etc. from toolbar).

I have created a boolean @is_in_ecommerce_p@ in default-master.tcl and can reference it etc, but..

how to set is_in_ecommerce_p so that it works consistently, ie 't' when in the ecommerce package, and 'f' for all others --without hard coding package_id or url references?

Here is an example failed attempt:

at end of default-master.tcl:

# In ecommerce package?
set ec_pkg_id [ec_id]
set is_in_ecommerce_p [expr $pkg_id == $ec_pkg_id]

in default-master.adp (for diagnostics):


<p>@is_in_ecommerce_p@, pkg_id:@pkg_id@ ec_pkg_id:@ec_pkg_id@</p>

results are same regardless of page requested from within bugtracker, API Browser etc:

 0, pkg_id:272 ec_pkg_id:511

Granted ec_id is object_id, not package_id. I figure there is a way to create an ec_pkg_id proc, maybe requiring a call to the db?

Also, isn't pkg_id (in default-master.tcl) supposed to change value depending on page requested?

hints etc much appreciated.

Okay, $pkg_id refers to acs-subsites.. (my tired eyes/lazy code reading)

changed default-master.tcl to:

    set ad_pkg_id [ad_conn package_id]
    set ec_pkg_id [ec_id]
    set is_in_ecommerce_p [expr $ad_pkg_id == $ec_pkg_id]

now ec_pkg_id and ad_pkg_id seem to match within ecommerce, but so does using:

    set ad_pkg_id [ad_conn object_id]

Should object_id's, package_id's or some other item be compared for this purpose?

Torben,

Another approach would be to set a property in some common ec adp component and then pass that on to the master template (unless I'm misunderstanding what you're attempting to do). I'm not at all familiar with the ec package, but a quick look at the www/index page indicates that a toolbar component is <include>ed. I'm making the assumption that the toolbar is common throughout all ec pages (granted, it's a long stretch).

If the toolbar is included in every ec page, you could place <property name="is_in_ecommerce_p">true</property> in toolbar.adp and check for it in the master template like:

<if @is_in_ecommerce_p@ defined>
...
</if>

Randy

Right, Randy. That's the approach I am using within ecommerce --to present the toolbar on pages according to aD coders wisdom. Basically grepping for toolbar, and replacing with the property tag you mention (using variable show_toolbar_p).

I'm hoping to use "is_in_ecommerce_p" as a switch to turn on site-wide spamming of the toolbar (ec_search_widget), and importantly to turn off "default show toolbar" within ecommerce. That way the historical wisdom of displaying the toolbar within ecommerce is retained (using show_toolbar_p and OR logic).

The problem is, how to define is_in_ecommerce_p in default-master.tcl?

Is  object_id and package_id the same for package instances, just different semantics?

I'm still not comprehending your intent...

What do you mean by "site-wide spamming of the toolbar"? Do you mean that you wish to display the toolbar on pages other than ec pages? And you plan to do that by placing <include src=".../toolbar>" in the master template?

I still think that it would be more straightforward to keep an  <include> in the ec adp pages. In other words, don't replace the existing includes with a property tag, but place the property tag in the include, and pass it on to higher-level templates. Maybe replace the "src=..." attribute of the existing <include> tag to bring in a simple file that just sets a property to indicate the request is coming from an ec page.

The [ad_conn package_id] is the object_id of the package instance mounted on the site-map at the requested location. You can obtain various properties of any site-node with the site_node::get* api. You could use [ad_conn package_id] or [ad_conn location] as the seed to obtain everything there is to know about any node, including the package_key (i.e. the package name).

By "site-wide spamming of the toolbar"? Do you mean that you wish to display the toolbar on pages other than ec pages?

Yes.

And you plan to do that by placing <include src=".../toolbar>" in the master template?

Yes, by wrapping include with a conditional template "if" tag.

Sorry for the gibberish previously posted. Information overload has a tendency to affect me that way. I had half a mind to post with. Unfortunately that half didn't realize its limitations.

It makes more sense to use variables: is_not_in_ecommerce_p and show_toolbar_p.

in default-master.tcl:

  set is_not_in_ecommerce_p [expr [ad_conn package_id] != [ec_id] ]

in default-master.adp:

<if @is_not_in_ecommerce_p@ true>
<include src=".../toolbar>
<!-- displays toolbar for pages outside ecommerce -->
</if>
<if @show_toolbar_p@ true>
<include src=".../toolbar>
<!-- displays toolbar for chosen pages within ecommerce -->
</if>

Thanks for the clarifications regarding ad_conn package_id and object_id, Randy!

ps. I think there will be some slight changes as I generalize the toolbar url etc. I'll post the final version here.

cheers,
Torben

Just stumbled on this jewel[1] that clarifies some other questions about a package referencing another package's url.

https://openacs.org/forums/message-view?message_id=26304