Announcement

Collapse
No announcement yet.

why doesn't this miva variable print?

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

    why doesn't this miva variable print?


    Why doesn't variable &mvt:global:schema_json; appear in the <head?.

    I have this code in my <head section

    This is the display logic of a MVT DO call

    fields="'g.product_code'">
    <mvt:assign name="g.schema_json" value="s.callvalue" />
    </mvt:call>

    <mvt:if expr="g.schema_json GT ''">
    <script type="application/ld+json">
    &mvt:global:schema_json;
    </script>
    </mvt:if>

    This variable is in my token list &mvt:global:schema_json;

    &mvt:global:schema_json;{ "@context": "https://schema.org", "@type": "Product", "@id": "https://www.xlerator-hand-dryer.com/mm5/merchant.mvc?Screen=PROD&Product_Code=XLTest2#prod uct", "name": "XL test2", "description": "Product typically ships from warehouse within 24 hours. Xlerator&reg Automatic Sensor Activated Hand Dryer dries hands fast and completely in 10 - 15 seconds! That's 3 times faster than conventional hand dryers. Excel hand dryers use 80% less energy saving your facility money! These hand dryers are designed to run on 15-amp service (making it great for older buildings)! The Xlerator&reg is GreenSpec&reg approved and qualifies for LEED&reg cre…

    Any ideas?


    Larry
    Luce Kanun Web Design
    www.facebook.com/wajake41
    www.plus.google.com/116415026668025242914/posts?hl=en



    #2
    I tested our new Claude MCP server on this question (with no other prompting). See if this helps:

    Your variable gets set, but not until after the <head> has already rendered. That's the problem.

    Miva processes the <head> (Global Header) before the product display layout. Your <mvt:call> that builds g.schema_json runs in the product's display logic, lower down the page. By the time that code runs and fills the variable, the head is already done. So when your <mvt:if expr="g.schema_json GT ''"> runs up in the head, g.schema_json is still empty, the condition fails, and the <script> never outputs. The token list shows a value because that view reflects the page state at the end, after the body has run.

    Two more things to fix while you're in there:
    1. &mvt:global:schema_json; HTML-entity-encodes the output. Your quotes become &quot; and your ampersands become &amp;, which breaks the JSON-LD even once it prints. Use <mvt:eval> to write the raw string.
    2. <mvt:call> returns the response one object at a time. A plain <mvt:assign name="g.schema_json" value="s.callvalue" /> keeps only the last object, and without flags="noparse" Miva tries to parse the response as HTML tags. Initialize the variable, add noparse, and concatenate.
    Option A: build it in the head, above the output. The product code is available in the head on a PROD page, so the whole block can live there:

    Code:
    <mvt:assign name="g.schema_json" value="''" /> <mvt:call action="[your existing action]" method="POST" fields="'g.product_code'" flags="noparse"> <mvt:assign name="g.schema_json" value="g.schema_json $ s.callvalue" /> </mvt:call> <mvt:if expr="g.schema_json GT ''"> <script type="application/ld+json"> <mvt:eval expr="g.schema_json" /> </script> </mvt:if>
    Option B: output the script in the body. JSON-LD doesn't have to be in the <head>. Google reads it anywhere on the page. If you'd rather keep the <mvt:call> in the product display logic, put the <mvt:if> + <script type="application/ld+json"><mvt:eval expr="g.schema_json" /></script> block right after the assign, in the same template. That avoids the head/body ordering completely.

    Then validate in Google's Rich Results Test and validator.schema.org. JSON-LD is the format Miva recommends, so your overall approach is fine.
    Thanks,

    Rick Wilson
    CEO
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Hello Rick:
      Thanks for the reply. The odd thing is that I am doing the same exact placement (right before the </head> tag on our other site's PROD page and it works just fine there.
      We get a nice Json scheme right before the </head> tag.

      Doesn't a MVT:Do call pause until the response is received?
      It's curious. In our PROD template there is a <head> tag at the top of the code. I tried putting the call there and that doesn't work either. Are you saying there is another <head> </head> section for this page?
      View source doesn't show that.
      I'm really puzzled and frustrated that this is so difficult to get done.
      Larry
      Luce Kanun Web Design
      www.facebook.com/wajake41
      www.plus.google.com/116415026668025242914/posts?hl=en


      Comment


        #4
        Again I'm just being the intermediary between you and our internal Claude MCP server and a couple skills, here's Claude's updated answer:

        You're right, and that rules out my first answer. mvt:call is synchronous: it waits for the full HTTP response before the template moves on. With the call sitting right before your output, sequence isn't the problem, so ignore the head/body ordering point I made earlier. Sorry about the wrong first answer.

        Since the exact same code works on your other site, your template logic is sound. The difference between the two sites is the data going into the call.

        Most likely cause: g.product_code is empty on this site's product pages.

        g.Product_Code only exists when it's in the URL query string (...?Product_Code=XLTest2). If this site uses SEO-friendly product URLs (/xlerator-hand-dryer.html), there's no Product_Code in the query string, so g.product_code is empty. The call then posts an empty code, gets an empty response back, the <mvt:if> sees nothing, and the <script> never prints. That also explains why moving it to the top of the head changed nothing: the global is empty everywhere on that page.

        The value that's always populated in a product template is l.settings:product:code. Miva loads it from the product record no matter how the URL is formed. Your other site probably uses query-string URLs, which is why g.product_code happens to be set there.

        Confirm it in 30 seconds. Drop this right after your </mvt:call> and view source:

        Code:
        <mvt:eval expr="'DEBUG g.product_code=[' $ g.product_code $ '] product:code=[' $ l.settings:product:code $ '] schema_len=' $ len(g.schema_json)" />
        If g.product_code is empty but product:code has the code, that's your answer.
        • If both have the code but schema_len is 0, the call itself is returning nothing (see the last note).
        Fix: give the call the right value.

        <mvt:assign name="g.product_code" value="l.settings:product:code" /> <mvt:assign name="g.schema_json" value="''" /> <mvt:call action="[your existing action]" method="POST" fields="'g.product_code'" flags="noparse"> <mvt:assign name="g.schema_json" value="g.schema_json $ s.callvalue" /> </mvt:call> <mvt:if expr="g.schema_json GT ''"> <script type="application/ld+json"> <mvt:eval expr="g.schema_json" /> </script> </mvt:if>
        On your other questions:

        There's one <head> in the rendered HTML, so view source is correct. Its contents come from more than one template though: the PROD page's own head, the Global Header, and Global Settings > HEAD Tag Content (store-wide). "Right before </head>" can live in any of those, so make sure the template you're editing is the one that feeds the PROD page.

        If the debug line shows a good product code but schema_len is still 0, the call is failing rather than returning empty. Check g.MvCALL_Error right after the call and confirm the action URL resolves from the server itself. Self-calls to the same store can fail on staging or dev domains over SSL, which would behave differently from your other site.
        Thanks,

        Rick Wilson
        CEO
        Miva, Inc.
        [email protected]
        https://www.miva.com

        Comment


          #5
          Originally posted by Rick Wilson View Post
          &mvt:global:schema_json; HTML-entity-encodes the output. Your quotes become &quot; and your ampersands become &amp;, which breaks the JSON-LD even once it prints.
          Isn't that incorrect? It's mvte:, not mvt: that does entity encoding, right?
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Thank for the help on this. I found the issue. Schema program fails creation on certain products resulting in an empty reply to the call,
            Cheers
            Larry
            Luce Kanun Web Design
            www.facebook.com/wajake41
            www.plus.google.com/116415026668025242914/posts?hl=en


            Comment


              #7
              Conclusion: Schema failure was due to registered trademark and copyright symbols in the item's description. Escaped them and issue resolved.
              Larry
              Luce Kanun Web Design
              www.facebook.com/wajake41
              www.plus.google.com/116415026668025242914/posts?hl=en


              Comment

              Working...
              X