1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Finding head section and body tag in front end

Discussion in 'XenForo Questions and Support' started by Dan Allen, Jan 15, 2015.

  1. Dan Allen

    Dan Allen Active Member

    We are looking at putting stripes around the outside edge of our XF installation. We have php files that need to be included, one in the head section of every page and another immediatly after the body tag, before anything else. I have taken a look at the file system, and the Resources tab above and unfortunately, I am not finding the information I am looking for too quickly. In fact I am concerned that this surgery on the code might be wildly difficult.

    Can you offer any tips on where to put a php include in the header and another on the body tag of every front end page?

    How about the admin pages? A working prototype of the stripes is available here. Deeper explanation of the stripes is here.

    upload_2015-1-14_23-28-31.png

    Thank you.
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    The PAGE_CONTAINER template is the one you need to be looking at as that contains the head and body tags.
     
    Dan Allen likes this.
  3. Dan Allen

    Dan Allen Active Member

    Glad to here it is simple
     
  4. Dan Allen

    Dan Allen Active Member

    Well, I went through quite a few folders but did not see the PAGE_CONTAINER element. Is there a document I should be looking at?
     
  5. Brogan

    Brogan XenForo Moderator Staff Member

    It's a template.

    upload_2015-1-15_15-57-26.png
     
    Dan Allen likes this.
  6. Dan Allen

    Dan Allen Active Member

  7. Brogan

    Brogan XenForo Moderator Staff Member

    You can't run php in a template like that.

    It may help if you explain what you are trying to do, but it sounds like the development forum may be the best place for it.
     
    Dan Allen likes this.
  8. Dan Allen

    Dan Allen Active Member

    Is there a way to do this?

    upload_2015-1-29_15-1-54.png
     
  9. Dan Allen

    Dan Allen Active Member

    Corrected spotting of where the arrow points
    upload_2015-1-29_15-5-48.png
     

    Attached Files:

  10. Brogan

    Brogan XenForo Moderator Staff Member

    The simplest way would be via the xen:callback tag.

    Create your php file, then call it in the template using:
    Code:
    <xen:callback class="example" method="test"></xen:callback>
     
    Dan Allen likes this.
  11. Dan Allen

    Dan Allen Active Member

    so if my file is called additionalphp.php...

    Is there a certain diretory where it needs to be stored?

    What does the callback tag looking like? Here is my guess, and I guess it won't work.:
    <xen:callback class="additionalphp.php" method="test"></xen:callback>

    also, how did you get the trick code block surrounding your code?

    upload_2015-1-29_15-19-14.png
     
  12. Brogan

    Brogan XenForo Moderator Staff Member

    Be aware of the limitations related to xen:callback: https://xenforo.com/community/threads/more-assorted-things.50098/

    A simple example would be:

    library\Example\Test.php

    Which would contain:
    PHP:
    <?php

    class Example_Test
    {
        public static function 
    getHtml()
        {
            echo 
    'Hello world';
        }
    }
    Then in the template:
    upload_2015-1-29_21-35-54.png
     
    Dan Allen likes this.
  13. Dan Allen

    Dan Allen Active Member

    Thank you, got it to work, using the example you provided. The objective was to put randomly colored stripes around the page. Here are three successive page loads:
    upload_2015-1-30_0-28-1.png upload_2015-1-30_0-28-50.png upload_2015-1-30_0-29-27.png

    Here is the callback in the template:
    upload_2015-1-30_0-33-0.png

    Here is the code:
    Code:
    <?php
    
    class Example_Test
    {
      public static function getHtml()
      {
         $colorband[0]['redlow']    = 255;
         $colorband[0]['redhigh']    = 255;
         $colorband[0]['greenlow']    = 150;
         $colorband[0]['greenhigh'] = 215;
         $colorband[0]['bluelow']    = 0;
         $colorband[0]['bluehigh']    = 60;
         $colorband[0]['targetWidth']   = 15;
         $colorband[0]['maxWidth']   = 3;
         $colorband[0]['minWidth']   = 1;
    
         $colorband[1]['redlow']    = 0;
         $colorband[1]['redhigh']    = 255;
         $colorband[1]['greenlow']    = 0;
         $colorband[1]['greenhigh'] = 0;
         $colorband[1]['bluelow']    = 0;
         $colorband[1]['bluehigh']   = 255;
         $colorband[1]['targetWidth']   = 25;
         $colorband[1]['maxWidth']   = 7;
         $colorband[1]['minWidth']   = 1;
         shuffle($colorband);
         $borderWidthTargetArray[0]=3;
         $borderWidthTargetArray[1]=3;
         $borderStyle='';
         $numStripeArray=0;
         $numStripeArrays = count($colorband);
         $ij=0;
         $betterArray=array();
         foreach( $colorband  as $key=>$stripes):
             $borderWidthTarget = $stripes['targetWidth'];
             $numStripeArray++;
             $borderWidthtotal=0;
             $borderWidthtotal8=0;
             $maxWidth=$stripes['maxWidth'];
             $minWidth=$stripes['minWidth'];
             while ($borderWidthtotal < $borderWidthTarget and $ij < 500):
               $borderWidthThisLayer=rand($minWidth, $maxWidth);
              $borderWidthtotal=$borderWidthtotal+$borderWidthThisLayer;
               $betterArray[]= $borderWidthThisLayer;
               $thisStripe =  $borderWidthThisLayer . "px solid " . "rgb("
               . rand($stripes['redlow'], $stripes['redhigh'])    . ","
               . rand($stripes['greenlow'], $stripes['greenhigh'])  . ","
               . rand($stripes['bluelow'], $stripes['bluehigh'])    . "
               );";
              $borderStyle .=  '#customwrap' . $ij
              . " {border-left:" .$thisStripe . "border-top:" .$thisStripe  . "border-bottom:" .$thisStripe . "border-right:" .$thisStripe ."z-index:999999;}
                           ";
               $ij++;
               if ($borderWidthTarget-$borderWidthtotal<=$maxWidth):
                 $borderWidthThisLayer=$borderWidthTarget-$borderWidthtotal-1;
                 $borderWidthtotal=$borderWidthtotal+$borderWidthThisLayer;
                 $betterArray[]= $borderWidthThisLayer;
                 $thisStripe =  $borderWidthThisLayer . "px solid " . "rgb("
                 . rand($stripes['redlow'], $stripes['redhigh'])    . ","
                 . rand($stripes['greenlow'], $stripes['greenhigh'])  . ","
                 . rand($stripes['bluelow'], $stripes['bluehigh'])    . "
                 );";
                 $borderStyle .=  '#customwrap' . $ij
              . " {border-left:" .$thisStripe . "border-top:" .$thisStripe  . "border-bottom:" .$thisStripe . "border-right:" .$thisStripe ."z-index:999999;}
                           ";
    
                 $ij++;
                 $borderWidthThisLayer=1;
                 $borderWidthtotal=$borderWidthtotal+$borderWidthThisLayer;
                 $betterArray[]= $borderWidthThisLayer;
                 $borderStyle .=  '#customwrap' . $ij
              . " {border-left:3px solid #000; border-bottom:3px solid #000;  border-top:3px solid#000;  border-right:3px solid#000;  #000;z-index:999999;}";
    
    
                 if ($numStripeArray == $numStripeArrays):
                   $borderStyle .=  '#customwrap' . $ij
                   . " {box-shadow:inset 0 0 1px  #000;}";
                 else:
                   $ij++;
                 endif;
               endif;
    
             endwhile;
         endforeach;
    
    
         echo '<style>' . $borderStyle  . '</style>';
         if (isset($betterArray)):
           foreach($betterArray as $key=>$better):
    
           echo '<div id="customwrap' . $key . '">';
    
           endforeach;
         endif;
    
    
      }
    }
    Link to working example
     

Share This Page