We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30564
    • 60 Posts
    Hi all, tried searching for this, but with no success. Simple(ish) question. I want to be able to set up my template so that it adds the <meta> tags as a chunk, however for index only I want to add the google verify tag. e.g.

    if pageid = 1
    meta chunk google
    meta chunk default
    else
    meta chunk default
    endif

    I’d like to extend the principal so that I could deselect my ditto summary pages from the print add-in as well, though to be fair the add-in does work properly, showing no text to print.

    Advice thoughts?
    TIA
    Regards
      • 10487 MODX Staff
      • 1,535 Posts
      The following Wiki article should get you going with this one: http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 30564
        • 60 Posts
        Thanks, however, at the risk of appearing churlish, does this mean that there’s no ’logic’ functionality within the template system itself? The suggestion does look to be a surprisingly complex approach to deal with, what is, at least in the google case, a single event in a site. Equally, does this imply that I end up with a variable which must be set for each page? Whilst the document describes it as a ’hack’ one can see how some find themselves in multi-template territory.

        Any other thoughts, suggestions, or clarifications if I’ve missed the point herein.

        Regards
          • 4041
          • 788 Posts
          Maybe something like this is what you are looking for, create a snippet and add one call to the top of your template where the code needs to be inserted.

          <?php
          /*   Google_Meta
          
          * create new snippet with this code
          * add the uncached snippet to the top of the normal template where you want the output to appear
            ex: [!Google_Meta!] - (set the default in the snippet)
            or pass the snippet an ID [!Google_Meta? &tID=`1`!]
          
          */
          // check if an ID was sent, if not use default (1)
          $targetID = isset($tID)? $tID : '1';
          $output ='';
          
          // gets the current page id
          $cpID = $modx->documentIdentifier;
          
          // compare ID's, if they match echo the output
          if($cpID == $targetID){
            $output .='Google Meta code here which will print';
            
            //or
            
            $output .='{{GoogleMetaChunkName}}';
          }
            
          return $output;
          ?>


          Hope this helps smiley
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 30564
            • 60 Posts
            Many thanks for the snippet code, it does exactly what I was hoping to do for the google verify insertion.

            By the by I applied it to my print issue as well. I’ve only 3 pages out of the site which I don’t require printing, so I used your code as a basis for this, thank you. The call from the template is simply [!PrintSwitch!]
            <?php
            /*   PrintSwitch
            
            * create new snippet based on google code from Breezer
              ex: [!PrintSwitch!]
            */
            
            $output ='';
            
            // get the current page id
            $cpID = $modx->documentIdentifier;
            
            // compare document ID against the 3 summary pages
            if($cpID == '3' || $cpID == '6' || $cpID == '28'){
                $output .='<div></div>'; //in case I wish to add message data later
            }
            else{
               $output .='<div class="Printer">[[PrintDoc? &print_doc=`43`]]</div>';
            }
              
            return $output;
            ?>


            Regards