Jump to content

Template File Structure


geekpete
 Share

Recommended Posts

Hi All,

First post here so wanted to start by saying how much I'm liking ProcessWire.  Come from an ExpressionEngine / CraftCMS background ;)

I'm building a backend type service website where I have about 10 'admin' pages to view orders, upload orders (as well as a few other entities) extract data etc.  We are not talking about millions of records, thousands a month top so I thought I could use the 'page for everything' approach.

Initially I was just going to use the PW 'backend' and let the end users onto it i.e. The part you log into by default at /processwire and write some modules but having things like the settings tab on pages and some of the other bits an end user might not understand made me feel my own frontend would be a better idea.

I've got things up and running with a custom login that uses the PW authentication system and am building a nav no problem, using selectors for data etc (which by the way are awesome!).

So now I've settled in a bit I've come to structure my template files better and have read here....

https://processwire.com/docs/tutorials/how-to-structure-your-template-files/

Delayed output looked like the most flexible strategies (and easy enough to implement).  However, bear in mind each of the pages are unique in their functions so essentially I have a header / nav etc, then the page specific block and then a footer.

The page specific stuff is quite large and a lot of the time HTML with a sprinkle of PW / PHP bits.  I didn't want to do this....

$main content="<div><ul>.........." ($main_content gets used in main.inc as per 'structuring' link above)  Its gets quite cumbersome with a large block not to mention I lose some nice features in PHPStorm as it just sees it as a string.

So what I've been doing is this....

<?php
require("./includes/login.inc");
require("./includes/init.inc");

$main_content = $page->render("partials/" . $page->template->name .".inc");

require("./includes/main.inc");
?>

I now need to keep creating the matching .inc files.  Is there a way I can use just the one template file file to set $main_content in some cunning way that enables me not to manage the string building? Am I approaching things right?

I know I can just include a header, splurg the content and then include a footer but I liked the 'Delayed Output' approach for the flexibility.

Sorry if its a silly question everyone, still learning, only a few days in and I'm no PHP demon, no giggling at the back hahaha

  • Like 1
Link to comment
Share on other sites

48 minutes ago, geekpete said:

Just found out about markup regions

Markup Regions are a godsend if you want to code HTML directly rather than adding it as strings to PHP variables.

48 minutes ago, geekpete said:

Any other ways

Alternatively you can use output buffering (which is what I preferred before Markup Regions were introduced).

<?php ob_start(); // $main_content ?>
    <div>Your markup</div>
<?php $main_content = ob_get_clean(); ?>

 

1 hour ago, geekpete said:

Initially I was just going to use the PW 'backend' and let the end users onto it i.e. The part you log into by default at /processwire and write some modules but having things like the settings tab on pages and some of the other bits an end user might not understand made me feel my own frontend would be a better idea.

For a project like yours I would be inclined to try building it within the PW admin as a first approach - you can do a lot with the admin (it's just an application built using the PW API) and it's pretty easy to tweak it with hooks and custom CSS. I think it would be much quicker that way.

@bernhard has written a helpful blog post for getting started with Process modules, and check out his Showcase topic for the kinds of things that are possible:

 

  • Like 2
Link to comment
Share on other sites

Hi and welcome!

12 hours ago, geekpete said:

I'm building a backend type service website where I have about 10 'admin' pages to view orders, upload orders (as well as a few other entities) extract data etc.

Advice: Definitely stay in the admin! ;)

I had exactly the same thoughts before I created my CRM because modifying the admin seemed totally complex and out of my scope. But once you get the concept it is REALLY simple and you get all the benefits that the pw backend offers (all fields, all functionality like login, sanitization, field collapsing, hooks etc). That's why I created the blogpost that Robin linked to (thx btw :) ).

The ROI (return on invest) of digging into the PW admin is huge and it will help you a lot to improve all your pw related work, because you will understand everything a lot better.

I wish you good luck and a lot of fun :) 

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

4 hours ago, bernhard said:

The ROI (return on invest) of digging into the PW admin is huge and it will help you a lot to improve all your pw related work, because you will understand everything a lot better.

This, every day of the week!  Always keep in mind that the PW admin is basically a blank page with a masthead (or sidebar haha), everything else is optional through roles and permissions. 

  • Like 1
Link to comment
Share on other sites

@geekpete,

Welcome to ProcessWire and the forums.

In addition to what has been said, especially the comment about roles and permissions, just remember to test your work/module as both a superuser and a normal user. Some stuff will not be viewable, editable, etc, by default for non-superusers. 

  • Like 2
Link to comment
Share on other sites

I just wanted to follow-up for anybody reading in a similar situation.  After spending more time with the admin and understanding things I can say using it as opposed to recreating an admin at the 'frontend' is 100% the way to go, will be saving a ton of time, so glad I got a good steer from you all.

Edited by geekpete
Typo :)
  • Like 6
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.
×
×
  • Create New...