Jump to content

What php code should I use to link the same html code?


Recommended Posts

Hi, I have created over twenty different templates for the same site.
In all of them, the same long piece of html code appears. 
Could someone suggest me the php code I need to write in the template files to link that piece of html code, which is always the same everywhere?

What strategies could I use to link it?

The problem is that this long piece of code that is identical everywhere, MAY change IN TIME. So, when I fix it, I would have to change it in all twenty template files.... 

 

Link to comment
Share on other sites

Create a new php file inside template folder (or a subdirectory of it, ex. "inc") and paste your html portion you want to include in all the other templates, save it.
Then, in all the templates, where you want that portion to appear just:

<?php include('path/to/partial.php'); ?> // replace the path with yours.

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

22 hours ago, 3fingers said:

Create a new php file inside template folder (or a subdirectory of it, ex. "inc") and paste your html portion you want to include in all the other templates, save it.
Then, in all the templates, where you want that portion to appear just:

<?php include('path/to/partial.php'); ?> // replace the path with yours.

 

Or you could use the wireIncludeFile-function of ProcessWire. I prefer this over the PHP include-function. 😉

<?php

wireIncludeFile('path/to/partial', [
	"foo" => $foo
]);

 

  • Thanks 1
Link to comment
Share on other sites

On 7/23/2021 at 11:57 AM, AndZyk said:

Or you could use the wireIncludeFile-function of ProcessWire. I prefer this over the PHP include-function. 😉

<?php

wireIncludeFile('path/to/partial', [
	"foo" => $foo
]);

 

Hi, is there a specific reason why you prefer the wireIncludeFile-function of ProcessWire instead of the php include-function?

Then... the foo code part... what is it for?

Link to comment
Share on other sites

5 hours ago, franciccio-ITALIANO said:

Sorry I'm ignorant, can you elaborate on what you mean by "markup regions"?

Hi, as shown by jacmaes, there are great docs about those markup regions but in case they looked a bit hard to dive in at first sight, do not hesitate to tell me, i would write some simple examples for you to see how great and simple they actually are and what you can easily do with them, as usual with pw, from the simple replacement of header and footer by one single file to more "funny" things 🙂

have a nice day

Link to comment
Share on other sites

22 hours ago, franciccio-ITALIANO said:

Hi, is there a specific reason why you prefer the wireIncludeFile-function of ProcessWire instead of the php include-function?

Then... the foo code part... what is it for?

I prefer wireIncludeFile because of these points described by Ryan in his blog post:

Quote
  • They receive all of ProcessWire's API variables, and optionally your own specified variables (in the same way demonstrated above).
  • They assume a starting point in /site/templates/, unless you point them somewhere else.
  • They will only allow files that are somewhere within the directory structures started by /site/templates/, /site/modules/ or /wire/modules/ … adding a little more safety.
  • The .php file extension is assumed for any files you give it, so you can optionally omit it. Of course you can use a different extension if you want to, but just note that if the file has a .php extension, it's optional to specify it.

The foo variable is just an own variable you can pass and use in the included file. This way you can keep track where you added variables.

 

Of course Markup Regions are also awesome and I like to combine Markup Regions with wireIncludeFile. I use Markup Regions for the whole blueprint of the templates and wireIncludeFile to split up large junks of code. Occasionally I use field templates for repeating fields markup. ProcessWire offers many ways to structure your code if you want to. 😀

  • Like 1
Link to comment
Share on other sites

1 hour ago, szabesz said:

Hi,

very nice cheatsheet, i use markup regions for all my websites 🙂 i hope @franciccio-ITALIANO will have a look at your post and fall in love with them too 🙂

have a nice day

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Zendex
      Hi,
      I am trying to make a site for a studio, and I wanted to set a specific hover effect for my text. I want the background of the text to be lit up in the full height of the nav bar but it doesn't do it. I showed the expected result in the png in the attached files. I will also set the code here below, the top part is a css reset.
       
      HTML:
      <!doctype html>
      <html>
      <head>
      <meta charset="UTF-8">
      <title>Zendex</title>
          <link href="style.css" rel="stylesheet" type="text/css">
          <link rel="preconnect" href="https://fonts.gstatic.com"> 
      <link href="https://fonts.googleapis.com/css2?family=Offside&display=swap" rel="stylesheet">
      </head>
      <body>
          <div id="nav_bar">
              <div id="Zendex">ZENDEX</div>
      <ul>
          <a href="contact.html"><li>CONTACT</li></a>
          <a href="films.html"><li>FILMS</li></a>
          <a href="about.html"><li>ABOUT</li></a>
          <a href="home.html"><li>HOME</li></a>
              </ul>
          </div>
          <div class="main"></div>
      </body>
      </html>
      CSS:
      @charset "UTF-8";
      /* CSS Document */
      html, body, div, span, applet, object, iframe,
      h1, h2, h3, h4, h5, h6, p, blockquote, pre,
      a, abbr, acronym, address, big, cite, code,
      del, dfn, em, img, ins, kbd, q, s, samp,
      small, strike, strong, sub, sup, tt, var,
      b, u, i, center,
      dl, dt, dd, ol, ul, li,
      fieldset, form, label, legend,
      table, caption, tbody, tfoot, thead, tr, th, td,
      article, aside, canvas, details, embed, 
      figure, figcaption, footer, header, hgroup, 
      menu, nav, output, ruby, section, summary,
      time, mark, audio, video {
          margin: 0;
          padding: 0;
          border: 0;
          font-size: 100%;
          font: inherit;
          vertical-align: baseline;
      }
      article, aside, details, figcaption, figure, 
      footer, header, hgroup, menu, nav, section {
          display: block;
      }
      body {
          line-height: 1;
          background-color: #6A6969;
      }
      ol, ul {
          list-style: none;
      }
      blockquote, q {
          quotes: none;
      }
      blockquote:before, blockquote:after,
      q:before, q:after {
          content: '';
          content: none;
      }
      table {
          border-collapse: collapse;
          border-spacing: 0;
      }
      /*-------------------------------------------------------------------------------------------------------------------------------------------------*/
      #nav_bar{
          overflow: hidden;
          position: fixed;
          top: 0;
          width: 100vw;
          height: 125px;
          background-color: #484848;
          border: solid 1px black;
      }
      li{
          font-size: 24px;
          text-shadow: 1px 1px 100px white;
          font-family: 'Offside', cursive;
          float: right;
          margin: 45px 50px 0px 0px;
          height: 125px;
      }
      #Zendex{
          font-size: 24px;
          text-shadow: 1px 1px 100px white;
          font-family: 'Offside', cursive;
          float: left;
          margin: 45px 0px 0px 100px;
          color: azure;
      }
      #home{
          
      }
      #about{
          
      }
      #films{
          
      }
      #contact{
          
      }
      ul{
          margin: 0px 50px 0px 0px;
          color: azure;
          height: 125px;
      }
      a:link{
          color: white;
      }
      li:hover{
          height: 125px;
          background-color: #6A6969;
          color: white;
      }
       

    • By hellomoto
      I can't tell what's wrong; my local development version appears just fine, but I copy over the site files and db online and the homepage content is not being contained. This is what it should look like (same site in the same browser, running on my localhost): http://imgur.com/UFZFzrd
      What could be the problem here? Sorry to bring up something so irrelevant to PW here, I just know that you all are a valiant and helpful group, and no one on StackExchange seems to even know what I'm talking about.
      Thanks a lot.
    • By DooM
      Hey guys,
      I'm using Form builder module by Ryan and I'm trying to render HTML success message after form is sent using value from this field:

      but it renders exactly as it is written in the field, not as HTML. To render it I just use echo
      <?= $successMessage ?> What am I missing?
       
      Thanks for any help. 🧒
    • By Marcel
      Hey, 
      - we made a page as admins
      - as admins each  <img> tag is loaded and images are displayed
      - we tested the page as a pre-definded test user which is "guest" (Admin Theme: Reno)
      - as test user each <img> is missing and so no image is displayed
      I checked this in dev-mode on firefox and chrome. Does anyone have an idea or has had similar issues?
       
      Thank you in advance.
       
      Marcel
    • By Lemoratoire
      Hi guys, 
      For a school work, I need to be able to write my own HTML code in the editor, but when it comes to "complexe" code such as a .DIV or a SRC, the "source" page doesn't recognize it. 
      So my question is the following: Is there a possiblity for me to enable the fact that I could work on a page by using my own html, without touching the .php doc?
×
×
  • Create New...