ARG

Template associated to an _include.php page: possible???

Recommended Posts

ARG    5

Hello. Sorry in advance for the super basic question, from a total begginer: 
-when I want to create a new template in the admin, I have to create firstly a ''new.php'' page in the site/template folder. 
-Is it possible to do the same in an ''_new-include-some-page.php''  in the site/template/include folder?
I was thinking to a solution: removing the Include folder, and put all the .php pages in the template folder.
But, I am sure I am missing something, and other solutions exist.
An advice?
Thank you for your time.

Share this post


Link to post
Share on other sites
monchu    18

yes it is doable

however, you don't have to create a file anytime you create a new template in admin. you create a template file if you want to 'view' the page using that template

  • Like 2

Share this post


Link to post
Share on other sites
ARG    5

Doable? 
Ok. I probably missed something.
I will digg deeper in the doc.
Thank you monchu.

Share this post


Link to post
Share on other sites

Not sure I'm getting exactly what you want to do.

You can specify a different file for a template. Edit your template and in the Files tab, look for "Alternate Template Filename". I've never tried pointing to a subdirectory there, but don't see a reason for it not to work.

You can, as monchu stated, simply not create the file. I use file-less templates all the time, whenever the frontend doesn't require an actual page to exist.

Share this post


Link to post
Share on other sites
SamC    182

I do something like this, see the 'includes' and 'views' folders. I find it easier structured like this but you can do it any way you like :)

structure.thumb.png.f999441737ad55fe3659bbf13c2f5018.png

I set templates to 'main' in the alternate template section:

alt-template-filename.thumb.PNG.153cc344e875ae8b7858068f9c64d94c.PNG

...then once you've created a page using the 'about' template (created in the admin), when you visit 'site.com/about', main is used to output the contents of 'views/about.php' and a couple of includes:

// main.php

<?php namespace ProcessWire; ?>
<html>
<head></head>
<body>
    <?php include("./includes/_header" . ".php"); ?>
    <?php include("./views/{$page->template->name}" . ".php"); ?>
    <?php include("./includes/_footer" . ".php"); ?>   
</body>
</html>

I never got used to the delayed output. I like the simplicity of this approach.

This is just one of the many ways you can do things in PW, experiment, have fun :) hope this helps.

  • Like 1

Share this post


Link to post
Share on other sites
ARG    5
On ‎2017‎-‎07‎-‎20 at 10:05 AM, SamC said:

This is just one of the many ways you can do things in PW, experiment, have fun :) hope this helps

This describes a kind of liberty ... (this is why I find Processwire so attractive).... but...
..''Is the technology an instrument of liberation or enslavement?'' 
You have four hours. GO !
Just joking :-)
Thank you for the answers: each of them open up the door a little more.

  • Like 2

Share this post


Link to post
Share on other sites
SamC    182
On 01/08/2017 at 1:42 AM, ARG said:

This describes a kind of liberty ... (this is why I find Processwire so attractive).... but...
..''Is the technology an instrument of liberation or enslavement?'' 
You have four hours. GO !
Just joking :-)
Thank you for the answers: each of them open up the door a little more.

Have some fun with it. There's no magic, it's all in the docs. Go to the docs, read, test, read some more, test again. This was a total boost for me at the beginning. The docs are excellent and explain a lot of things. For example, you could start here:

https://processwire.com/api/variables/pages/

What I'm saying is, the help pages link so well together that every time new questions are kicked up, the answer is just a few clicks away. And this forum is phenomenal for support. Stick with it, you'll be able to make some cool things in no time. Once you find a way that suits you in terms of organising your data in your site, the templates, fields etc... then it's just a matter of getting stuck into the docs to find a way to print these values to a webpage. Further in, you'll probably want to do some more complex things with the data, but deal with that when you get there.

  • Like 1

Share this post


Link to post
Share on other sites
ARG    5
1 hour ago, SamC said:

you'll be able to make some cool things in no time

Oh no ! Cool things need time to be done. The difference between mediocrity and quality, is, frequently, the addition of time to talent, and work. 
But I am patient...
Thank you again.

  • Like 2

Share this post


Link to post
Share on other sites
szabesz    1,384
12 hours ago, SamC said:

Once you find a way that suits you in terms of organising your data in your site, the templates, fields etc...

Yep, it is worth spending the time on this stage, I 100% agree! This is the key to get to speed with ProcessWire based development.

  • Like 1

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By EyeDentify
      Simple example for loading template specific CSS file.
      This example asumes that you have your CSS file in a directory relative to template root.
      Like:
      templates/css/my_template_specific.css
      Also i use in the template a simple text field to hold the name of the CSS file i want to load.
      I call this field 'css_file'
      Use what you feel comfortable with.
      So in your header section of the DOM notice the "page specific CSS" part?
      Thats were the magic happens. What happens is that we check to see if the file exists in the CSS dir relative to template root.
      And if it does we load it. Simple and effective.
      I load all other CSS that is used all over the site in global_styles.css first.
      And make sure you load template specific last, because then you can easily override CSS in global.
       
      DOM header example:
      <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title><?PHP echo($page->title); ?></title> <!-- main CSS --> <link rel="stylesheet" href="<?PHP echo($config->urls->templates); ?>css/global_styles.css"> <!-- page specific CSS --> <?PHP /* Use relative path in file_exists() */ if(file_exists('css/' . $page->css_file)) { echo("<link rel=\"stylesheet\" href=\"{$config->urls->templates}css/{$page->css_file}\">"); } ?> </head> <body> Thats my way of doing it. I am sure there is plenty of more ways to do it. This is for the newbies or anyone that wants more options.
      Good luck with your CSS out there in Cyberspace.
      Cheers from EyeDentify
    • By zaib
      I've a page "blog" which have child pages (blog posts). Right now I've 11 pages (blog posts) and I'm fetching all the posts in my "blog" pages which displaying fine, Issue is only 10 results are showing this is how I'm fetching
      $entries = $pages->find("template=blog-entry"); foreach($entries as $entry){ <a href='{$entry->url}'>$entry->title</a> }  
    • By MilenKo
      Hello all. I know it might sound silly, but wanted to check how are you guys proceeding if in the theme development you have a need of some fields that are repeating in several templates. For example, I am having an image field that can be used as the site logo in "Settings" template or as to show the page image in the markup of the inner page template or else. I am aware, that if I leave the resizing in the markup, than the field can be used on multiple templates, but the field has some specific label/description, notes and/or placeholder that would be not-related. 
      Sticking to the logo example, I have a label saying: Add your logo image here. So if I use the same field for something else, the same text would show while editing the new next page calling for image.
      How are you guys taking care of this? Are you creating specific fields for every aspect of your theme or there are some tricks I am missing in the big picture?
      P.S. Besides the descriptive text of the field some might require to have a single image and some an array (e.g. you don't need to upload multiple logos, unless you want to randomize or call one based on some criterias, but for a gallery - sure I would have multiple)
    • By mike62
      I'm new to PW... I'd like to have some blog posts displayed on our homepage based off the attached mockup.
      I want each post to use a slightly different layout.
      Is this possible?

    • By rocket
      Noob to Processwire. Trying to convert some older sites to Pwire. I am having trouble including a legacy form class into my templates:
      If I embed the php directly in the template, it works. But if I use include statements, the form object returns null.
      This works:
          use formbuild\Form;
          session_start();
          $form = new Form(init1, 'init2', ...');
          $form->param1 = ...;
          $form->param2 = ...;
          $form->param3 = ...;
       
          $form->render();
      -----------------------------------------------------------------------------------------
      This fails:
          include_once ($config->paths->templates."forms/form1.php");
          $form->render();
      ____________________________________________________________________
      My referencing is OK, no error message. The only code that cannot reside in the include file are the following lines:
          use formbuild\Form;
          $form = new Form(init1, 'init2', ...');
      My PhP is rusty, maybe that is the problem, but it could be something about Pwire, namespace maybe. I have tested it outside Pwire and no problems.
      Please advise. Thanks.