lost password?

home
•  xaraya +
•  rails
•  django
•  webdev
•  xamp
•  musings

rss
Tag this page
   

» Blogs that link here
last modified: Nov 07, 2006
(first posted: Aug 25, 2006)
(1592 Reads)
keywords: articles BL Template block layout properties xarpages
Permalink

Dynamic Extendable Templates in Xarpages

I really wish we could include blocklayout (BL) code in textarea fields. But we can't (now anyway). So, here's a few techniques for dynamically extending your templates, one of which involves making your own property type.

To begin we'll assume we're in the Xarpages module, have a page type called "html", and thus have a template named page-html.xt (residing in mytheme/modules/xarpages/).

Now, suppose you want to include some content that requires using Xaraya block layout (BL) tags.

The way Xarpages works you'd need separate Item Templates for each page that has custom BL in it. That's ok, i guess, except that my templates usually contain other layout and navigation and stuff so you'd need to make sure when changes are made, all are updated.

Instead, I use a dyanamic data (DD) field to dynamically extend the one template.

Inserting Content From Another Module

Here's a specific example: your About section is a small hierarchy of pages, one is Board of Directors, another is Management, and a third is Partners. And suppose each of these are implemented as separate pubtypes in the Articles module. You want to show them on separate xarpages (for various reasons, not the least of which so they'll appear in an xarpages menu block).

I could have separate item templates for each of these pages, which call the corresponding module function, such as

#xarModFunc( 'articles', 'user', 'view', array( 'ptid'=>'12' ) )#

where "12" is the id of the "directors" pubtype. And two additional templates would each specify the pubtype id's for the others-- that being the only difference between the 3 of them.

(Note, I had used <xar:module main="false" ... tag here, but Jojo says its not good practice and to use the xarModFunc() instead).

Instead, I create a DD textbox field called "xarfunc" that must be in the format:

    modname:functype:func

or, if modname is "articles", then it should be

modname:functype:func:ptid

Thus, i the first example, my xarfunc field contains:

    articles:user:view:12

Then, in the page-html.xt template, I include the code:

<xar:comment> quick wayto pull in content from another module, 
the field xarmodule is formatted module:type:func </xar:comment>
<xar:if condition="!empty($current_page.dd.xarfunc)">
<xar:set name="mod">explode(':', $current_page['dd']['xarfunc'])</xar:set>
<xar:if condition="isset($mod[3]) and $mod[0] eq 'articles'">
#xarModFunc( $mod[0], $mod[1], $mod[2], array('ptid'=>$mod[3]) )#
<xar:else />
#xarModFunc( $mod[0], $mod[1], $mod[2] )#
</xar:if>
</xar:if>

I'll usually sandwich this between a Body textarea field and a Conclusion textarea field, so there can be regular content before and after the list. An example where I use this, see http://www.abi-nh.com/about/directors and http://www.abi-nh.com/businesses

 

Inserting Arbitrary Blocks

If you prefer to use blocks for inserting content from another module, such as the Article topitems block, you could do a similar thing as above but the textbox contains the block instance name instead. Thus, different blocks appear on different pages.

If you make a textbox field named "xarblock", then your template would contain:

<xar:if condition="!empty($current_page.dd.xarblock)">
<xar:block instance="$current_page['dd']['xarblock'])" /> </xar:if>

 

Including Other Templates

[Note: this section updated because I recently added the BLT property to the Xaraya core]. 

If your programming requirements are even more extensive, you still can avoid making separate item templates by including other BL templates.

At this point you might be asking, what's the point? Well, on www.myvbi.org I have a page template (mytheme/pages/default.xt) that defines the overall page layout, <head>, banner, footer, etc. Then the middle section is defined by the xarpage item template (page-html-vbi.xt), which has the left column, intro paragraph, perhaps one or 2 blocks, etc. Finally, inside this middle section there may be dynamic content thats not satisfied by ordinary html or other xaraya property types.

For example, on http://www.myvbi.org/grow/program/nh . You can see the middle section (below the banner area and above the footer) which comes from the xarpage item template is pretty complicated but stays the same for most of the pages in this section of the site.

The categories list in the center is specific to this page, so I made a separate little template for it named "vbi-freehelp-body.xt" and put it into mytheme/modules/xarpages/includes/ directory.

In my page type I have a DD field named "body_include", with property type "BL Template". In the validation, I specify type as "module", and module name as "xarpages". 

When you create/edit a page, the dropdown list now contains all the templates you've added to the includes/ directory. Its nice because these can be as small or large as needed and they're reusable on different pages.

Finally, add this to your page-html.xt template

<xar:if condition="!empty($current_page.dd.body_include)">
    <xar:data-getitem name="$properties" module="xarpages" itemid="$pid" itemtype="$current_page['dd']['itemtype']" />
    <xar:data-output property="$properties['body_include']" />
</xar:if>
 

Note that unlike when you include an <xar:template> tag directly in your templates, when you use the BLTemplate property the included template does not inherit variables available in the calling template. So if you need to share values, either pass them with the "bltsubdata" validation field, or use the cache (xarVarSet/GetCached).

 

 

Dynamic Extendable Templates in Xarpages

Posted by: Alexander on May 14, 2007 05:18 PM
Thanks. Very useful

#

Dynamic Extendable Templates in Xarpages

Posted by: Alexander on May 14, 2007 05:55 PM
You wrote: >Note, I had used <xar:module main="false" ... tag here, but Jojo says its not good practice and to use the xarModFunc() instead Why?

#

Dynamic Extendable Templates in Xarpages

Posted by: Alvaro on October 25, 2008 07:48 AM
Can you plese give me a hint about ho to use the "bltsubdata" validation array? I'm not able to make it work.

#

Post a new comment

How many days in a week?

Name :