Skip to main content

Once again ONCE

Back in September of 2007 I wrote a post here about using the ONCE RTML operator to speed up the yahoo store editor. In that article I mentioned that the ONCE operator has two modes, one to evaluate the operator's body once per publish and the other, once per page. What I said there was that while ONCE :publish has great potentials and practical uses, ONCE :page wasn't too useful. Well, today I must correct that statement, as I recently discovered two ways to use ONCE :page.

To recap, a statement like this:
CALL :some-template
will evaluate the body of the ONCE operator once on the page and output its result. So in the example above, it would only call the template called some-template once on each page and output whatever some-template writes to the page. So far so good, if you have this block only once on the page, then having ONCE :page in it makes no difference.

Now consider this: some Yahoo! Stores have a breadcrumbs trail both at the top and at the bottom of the page. In case of long pages, this can help visitors navigate the site. In that case, you would have to call the breadcrumbs template twice on each page.

To digress here a little, the breadcrumbs template typically walks through the pages leading up from the current page to the home page (index), and puts up a hyperlink for each page along the path, something like this:

Home > Countertop Appliances > Beverage Appliances > Electric Tea Kettles

Ok, what's the problem with this? Maybe I'll write another post about this, but the main problem with breadcrumbs is that when writing breadcrumbs code, you have to use either the WITH-OBJECT or the FOR-EACH-OBJECT operator to switch the context to each of the pieces in the breadcrumbs trail, so that you can grab the name of each of those pages (in the above example, Home, Countertop Appliances, Beverage Appliances). Using the WITH-OBJECT or FOR-EACH-OBJECT operator is "exensive", meaning it slows down your editor and your publish process, because the editor has to "fetch" those pages from storage (disk). So, if you have two breadcrumbs trails, you will do this twice per page. That's where ONCE :page comes in!

CALL :breadcrumbs.


CALL :breadcrumbs.

Take a look at the above code segment. Here, you have the top breadcrumbs, the page body (where the .... part is), and then the bottom breadcrumbs trail. However, in this case, the actual breadcrumbs code is evaluated exactly once, not twice. You essentially get the second one for free!

My second idea came from a small project I was working on recently. In a Yahoo Store, we had pages that had 3 types of "components" you could order: a kit, the individual kit components, and the tools used to put a kit together. We had three "references"-type fields for these called (you guessed it) kit, kit-components, and tools-used, so data entry personnel could put product IDs in all three of these fields. The twist was, they wanted to label each of the "sections". Below is a sketch of this setup.

In RTML, you could write three separate loops to achieve this:

<... generate one line of the table ...>
TEXT "Kit Components"
FOR-EACH-OBJECT @kit-components
<... generate one line of the table ...>
TEXT "Tools Used"
FOR-EACH-OBJECT @tools-used
<... generate one line of the table ...>

In our case, the table was a little complicated, so splitting the code up into three segments was going to be a problem, but luckily, I was able to solve this using ONCE :page.

Instead of having three loops, I combined the 3 fields into one list using the APPEND operator, so I could have just one loop, but then, I used ONCE :page to put up the headers:

WITH variable kit
value @kit
WITH variable kit-components
value @kit-components
WITH variable tools-used
value @tools-used
WITH variable list
value APPEND
WHEN POSITION element id
sequence kit
ONCE :page
TEXT "Kit"
WHEN POSITION element id
sequence kit-components
ONCE :page
TEXT "Kit Components"
WHEN POSITION element id
sequence tools-used
ONCE :page
TEXT "Tools Used"
<... generate one line of the table ...>

This is somewhat simplified of course, the headings had to go into their own table rows with table cells spanning the entire table width, but that's not the point here.

The point is, that using ONCE :page for the headers, I didn't need to care about where to output the headers, it just worked! Even if I had 20 items in, say kit-components, the "Kit Components" heading would only appear once thanks to the fact that it was output within a ONCE :page construct.

One final point: why did I save the values of the "kit", "kit-components", and "tools-used" properties into local variables? Well, this is a common mistake I see from RTML programmers: they forget that once they are inside a FOR-EACH-OBJECT or WITH-OBJECT expression, they are referencing the local properties of another page. By saving these properties in local variables, I can be sure that I can reference those instead of accidentally grabbing the values from each of the component pages.


Popular posts from this blog

What is product-url anyway?

I keep having to field questions about the product-url field, and since it came up yesterday, I figured I'd try to clear up all the confusion about it.

So the name product-url suggests that whatever you type in there will become the URL of that product. Unfortunately, this is not the case, or rather, not in the intuitive way. The URL you enter there will be used as the URL for that product in Yahoo Shopping, on the built-in search results page, and on the shopping cart page, however, the URL you type in there DOES NOT actually change the physical URL of the page.
What is the URL of a page in a Yahoo Store? In any Yahoo Store built in the store editor, the URL of a page is the store's domain name and the page ID + .html. For example, in my store at, I have a page whose id is rtml101, thehrefore, the URL of that page is
Why would you want to change the URL? For SEO reasons, it is believed to be better to have a URL that includ…

Referencing Files from Yahoo! Web Hosting Securely

Now that hopefully most of you you have your stores secured (if not and need help, we offer a Secure Storefront Preparation Service here), you may have been faced with the question of how to reference files (images, CSS, JavaScript, src) if those files are stored on your Yahoo! store's web hosting account. Obviously using the old HTTP: method won't work, so something like this

< img src="" />

will not work. Nor can you simply change the http: part to https: , because as of this writing, only the store editor portion of a Yahoo! Store can be made secure, the web hosting portion cannot.

First a side note: if this sounds totally Greek to you because you have never heard of the web hosting part of your Yahoo! Store, you may have a legacy Yahoo! store account and not a Merchant Solution one. With a legacy store account you will only have the store editor part and no hosting account, in which case none of this applies to you.

The good n…

Really Quick Trick to Improve Page Load Speed of a Yahoo Store a Little Bit

With Google getting more and more aggressive about wanting web sites to be quick to load (particularly on mobile), we often find ourselves trying to find even the smallest of tweaks to nudge up that page speed score even if by a tiny bit. Here is a quick trick you can do completely on your own, without having to ask a developer, that will probably bump up your Google PageSpeed score by a couple of points.

First a short disclaimer: this trick is only applicable if you have enabled the Yahoo! Badge in your Store Manager, under Live Insights & App Gallery.

Before you start, you may want to check your site's Google PageSpeed (the home page is a good place to start) both as a benchmark, and also to get a glimpse at how fast (or slow) Google believes your site (or home page) is. Here is the link:
Ok, so if you did enable the Yahoo! Badge, your site includes a small Yahoo Live Store badge, much like this:

When you hover over the …