24/7 Support - 800.608.6482

Miva Merchant Community Forums

Thread: Discovering all the items in a template

  1. #1
    Join Date
    May 2009
    Posts
    170

    Default 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. #2
    Join Date
    Mar 2006
    Posts
    11,189

    Default 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.

  3. #3
    Join Date
    May 2009
    Posts
    170

    Default 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.

  4. #4
    Join Date
    May 2009
    Posts
    170

    Lightbulb 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 at 02:38 PM.

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •