[docs] Re: The mysterious [output] tag

Ethan Rowe ethan at endpoint.com
Fri Oct 8 17:12:54 EDT 2004


Ethan Rowe wrote:

>
>>> Does anybody know what the [output] tag does, used extensively in 
>>> the admin UI_STD_HEAD?  It's not documented, and I can't find a 
>>> definition for the tag anywhere (yet).
>>>   
>>
>>
>> It's a new feature in 5.1 (I think) that allows you to queue up 
>> output for the page in chunks, then output them at the end, possibly 
>> in a different order. I've only used it once, for some End Point 
>> project I now forget. But it's used in the admin.
>>
>>  
>>
> Yes, it's used quite a bit for the admin.  And the reason the 
> definition for the tag is so difficult to find is because it's more or 
> less defined in Vend::Parse::start() -- it's a special tag that simply 
> results in a call to Vend::Parse::destination(); you get to assign a 
> name to an alternate "destination" for the stuff that follows the 
> tag.  Each time you call this, you put a new destination on a stack 
> (@Vend::Output, and the index of that stack gets pushed on 
> @%Vend::OutPtr{<destination-name>} as well), and various output 
> filters to run on that particular destination's content prior to 
> returning go in %Vend::OutFilter{<destination-name>}.
>
> In Dispatch.pm's response() sub, it returns all of these different 
> chunks in the order specified by the @Vend::Output stack.  While I 
> haven't seen a way to manipulate the ordering of that stack (yet), I 
> suppose you could fiddle with it from a global sub if you wanted to.
>
>> There used to be a simple way, but I'm not sure in the new admin. If 
>> you need an answer (for the GiftNet stuff, I presume), I could look 
>> more, but if it's not urgent I'm going to put it off. :)
>>  
>>
Since I have an answer to this, I'll answer my own question and maybe 
it'll help somebody else out sometime.

In the admin, the pages rely on UI_STD_INIT to set up variables and 
whatnot, then UI_STD_HEAD to deal with access control, menu layout, 
etc.  UI_STD_HEAD makes heavy use of the [output name=some_namespace] 
tag, assigning different major sections of the page to different 
namespaces in the output stack.  However, UI_STD_HEAD never does any of 
the stuff one might expect as far as setting up the basic HTML goes; it 
doesn't provide the open <HTML>...<HEAD>... tags or any of that; it just 
starts right in setting up menus under these different namespaces.

Ultimately, and somewhat counterintuitively, the page gets more or less 
rebuilt with the UI_STD_FOOTER variable.  This uses the [unpack]...some 
content...[/unpack] tag.  [unpack] in combination with [output] is 
outrageously powerful and I failed to find any documentation on this.  
Anyway, basically, it expects that the content provided within the 
[unpack] container tag will function as a template, against which we 
evaluate the different namespaces on the output stack.  So, if the 
UI_STD_HEAD we set up a couple of menus as:
[output name=top_tabs]
    [menu
       name=Top
       .....
       ...
    [/menu]
[output name=second_tabs]
    [menu
       name=second
    .....
    [/menu]
  
And then we have a "template" in UI_STD_FOOTER of:
[unpack]
<html>
<head>
    <title>Stupid Example of Output and Unpack</title>
</head>
<body>
    <div class=top_menu>{{TOP_TABS}}
    </div>
    <div class=second_menu>{{SECOND_TABS}}
    </div>
</body>
</html>
[/unpack]

All the output that went into the top_tabs and second_tabs spaces will 
get substituted into the corresponding {{TOP_TABS}} and {{SECOND_TABS}} 
tokens above.  Furthermore, as with the templates used in the mass 
mailer and other places, you have some conditional logic available to you:
{{SPACE?}}blah blah{{/SPACE?}} will output "blah blah" if SPACE is 
populated.  You could embed other tokens within this if you wanted.
{{SPACE:}}blah blah{{/SPACE:}} will output "blah blah" if SPACE is 
empty.  You could also embed other tokens in this.

For instance, {{SPACE?}}<div 
class="happy_space_class">{{SPACE}}</div>{{/SPACE?}}

So, in the admin UI, the footer (UI_STD_FOOTER) includes a file within 
the [unpack]...[/unpack] call as:
[unpack]
[include file="include/templates/ui_[either][scratch 
display_class][or]type1[/either]"]
[/unpack]

Then look at your interchange core directory, 
lib/UI/pages/include/templates and you'll see a bunch of ui_typeX files 
that provide the template functionality.

If you want to see the code, the critical things are:
- lib/Vend/Page.pm sub templatize
- code/SystemTag/unpack.coretag
- less lib/UI/vars/UI_STD_FOOTER
- vim lib/Vend/Parse.pm sub destination (which is basically the 
functionality behind the output tag)

-- 
Ethan Rowe
End Point Corporation
ethan at endpoint.com



More information about the docs mailing list