Announcement

Collapse
No announcement yet.

Discovering all the items in a template

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Discovering all the items in a template

    I'm just throwing this out there and hoping for a good answer.

    Has anyone created a function that parses a template file and extracts a list (array) of items that are used? Or do I just always compile and render with all of them and let the page sort 'em out?

    Taking another stab at creating my own rendering system... I have something working, but dealing with items is always bringing up one more gotcha.

    Thanks

  • #2
    Re: Discovering all the items in a template

    Do not compile with all of them assigned. Several component modules have a function that runs before the template is even parsed. If you assign their items, even without a token on the page, that module could eat up resources needlessly. In some cases those modules running on pages they were not intended for can conflict with other modules and I've even seen where it stopped a page from displaying.
    Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
    Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
    Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
    Facebook http://www.facebook.com/EmporiumPlus
    Twitter http://twitter.com/emporiumplus

    Comment


    • #3
      Re: Discovering all the items in a template

      Thanks for the advice. Please keep in mind that this is not for a Merchant store, but something of my own design so things like order and conflict are under control. I'm just talking in the grand scheme of things.

      The best end result would be at compile time of the main page, something reads though the code and picks up that I'm using the global header and footer items, the navigation item, and the profile display item, then save that off to a table so at render time I know which bits I'll need.

      Comment


      • #4
        Re: Discovering all the items in a template

        I found a reasonable solution. It's always the simplest answers that work best.

        Code:
        <MvFUNCTION NAME = "Parse_For_Items" PARAMETERS = "src, array var" STANDARDOUTPUTLEVEL = "">
        <MvASSIGN NAME = "l.item_count" VALUE = "{ [ g.site_lib_db ].Screen_Item_Load_All( l.items ) }">
        <MvASSIGN NAME = "l.array_count" VALUE = "0">
        <MvASSIGN NAME = "l.count" VALUE = "1">
        
        
        <MvWHILE EXPR = "{ l.count LE l.item_count }">
        <MvIF EXPR = "{ len( l.src ) NE len( glosub( l.src, '<mvt:item name="' $ l.items[ l.count ]:item_code, '' ) ) }">
        <MvASSIGN NAME = "l.array_count" VALUE = "{ l.array_count + 1 }">
        <MvASSIGN NAME = "l.array" INDEX = "{ l.array_count }" VALUE = "{ l.items[ l.count ]:item_id }">
        </MvIF>
        <MvASSIGN NAME = "l.count" VALUE = "{ l.count + 1 }">
        </MvWHILE>
        
        
        <MvFUNCTIONRETURN VALUE = "{ l.array_count }">
        </MvFUNCTION>
        Last edited by Scott McCollough; 01-09-13, 02:38 PM.

        Comment

        Working...
        X