ARG

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

Recommended Posts

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

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

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

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
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
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
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
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 jtborger
      Hi,
      Yesterday I found out about the relatively new markup regions functionality and I love it. The ease of use and simplicity is just what I think is typically ProcessWire and is why Im still happy I chose for PW four years ago when changing CMS/CMF. So thanks Ryan for your vision and all you put into it.
      That said, Im running into an issue I'm not sure what to think of it.
       
      I have enabled markup regions in config.php and it does what I suppose it should: it replaced and all. Very neatly. 
      The only thing I discovered is that while Im debugging some issues and I use var_dump to echo some stuff, it does that two times in a row. And this only happens when useMarkupRegions is enabled.
      I dont get this, does it mean the template file gets called twice (and thus the script is run twice?) or is it only displayed twice, where the first time most output is erased and /or replaced by the substituted output?
      I don't really get whats going on there. Is this behavior normal when using markup regions?
      Thanks!
       
    • By mike62
      I'm working on a page and it's showing up differently when I'm logged in. It's not that a field is set to private or anything, because it's still pulling data from that field. It looks like the "public" view is simply using an old version of the template (home.php), and the logged-in view is using the current version of home.php. See attached screenshots.
      Is there something that caches template files? Is there a way to force it to use the most recent version of the template?
      EDIT: I found the Pro Cache module and cleared it. That seemed to help. 
      Thanks,
      -Mike


    • By mike62
      I am new to PW, and am trying to get an image to display, from a field in my template. Here's the code I'm using:
      <?php $image = $page->home_header_image; echo "<img src='{$image->url}' alt='{$image->description}' />"; ?> I'm following the tutorial on this here.
      When I save the template and reload the page, the path to the image is incomplete. If just echoes:
      <img src="/site/assets/files/1/" alt=""> It omits the name of the image, at the end of the path.
      Here's the site I'm working on:
      http://dev.delucaswpg.webfactional.com
      A couple caveats:
      I'm using ProcessWire 2.3.0 (tried updating the site and everything went berserk because of some plugin dependencies; point being: I can't update to the latest PW). I tried using the ->size thing and it gave me an error, saying it couldn't use 'size' in this context. Which I also thought was weird. Any ideas? Thanks!
    • By Violet
      I originally created my template files thinking I'd only ever need 3 and not worrying about if I repeated bunches of common code there (yes, bad practice, I know). I figured I'd just manually/copy-paste to change any common code in all 3 as needed. So of course, fast-forward awhile, and I'm now up to 6 template files with possibly a few more to come, and decided it was high time I made the switch to keep the common parts in their own unique files for ease of editing. So I therefore went back and read Ryan Cramer's tutorial "How to Structure Your Template Files".
      OK. I tried out the "includes" command mentioned in the tutorial on a test template. The resultant web page physically functions as expected, but my question here is, "Is the practice I'm showing below OK in terms of variable usage?" If not, what approach should I be using? 
      I've tested it out and the variables do populate as expected in the final result, but is it OK for me to do it like this or is there the chance that some of the variables won't be passed properly?
      Here is what I  mean (only the relevant portions of code shown to illustrate):
      ... <aside> <h3>Three Random Posts</h3> <!-- get the list, then display it --> <?php $itempages = $pages->find("template=my-post"); $shortlist = $itempages->getRandom(3); $shortlist->shuffle(); $itempagezero = $shortlist->eq(0); $itempage1 = $shortlist->eq(1); $itempage2 = $shortlist->eq(2); ?> <?php include("./INC_displaylist.php"); ?> </aside> <?php include("./INC_footer.php"); ?> </body> </html>
      The possible issue here is that the INC_displaylist.php file outputs field data from $itempagezero, $itempage1, and $itempage2. Is that OK? I wanted to split the variable assignments and the output separately. This is because, based on the exact template I'm using, I will sometimes choose to populate $itempages via different selectors in the $pages->find command in different template files, although all templates will display an identically-formatted list of 3.
      By contrast, I wouldn't expect any variable issues with including the INC_footer.php file as shown above, since I'm not using any variables in the footer that aren't first referenced in that same footer.
      So am I doing it OK here or should I be populating these variables somewhere else to ensure they're recognized properly by INC_displaylist.php? If I need to do it somewhere else, where should I populate these?
    • By Peter Knight
      Is the template name a value which I can display?
      I've read the API docs re. template names and tried a few things including below but nothing works so far.
      Template is: {$page->$template->name} FYI I'm building a small 'helper' section in a footer which is only visible to admins and it will display page ID, template name and a link to edit the page.
      Everything working apart from displaying the template name.