Jump to content

Recommended Posts

Posted

So in the Markup Regions output strategy, the docs seem to suggest that we can render markup using a different base to _main.php, for use on specific pages (like rss feed, homepage, etc) if needed. Have I understood that correctly?
https://processwire.com/docs/front-end/output/markup-regions/

It says "we can do so by editing the template settings in the ProcessWire admin to use a different file, or no file at all, when appropriate. (This is found in Setup > Templates > [choose a template] > Files [tab])."

I'm not sure, however, what setting I should change here. Let's say I want this template to apply Markup Actions to 'base.php' instead of _main.php, where would I set that here? Most of my confusion stems from the "Prepend" and "Append File" wording... 

I'd really appreciate any help 🙂 Thanks

image.thumb.png.72b4e48853aa9f623eaae73f1a80aa83.png

Posted

Thank you, @monollonom. I suspected it was that but I wasn't sure. 

While I have you 😄 - If I use multiple base files like _main.php in this way, do I need to change anything in config.php or am I good?
Thanks again.
 

Posted

The idea is to have the _main.php be the base for most of your templates and then on a case-by-case basis disable it per template and specify another appended file, e.g. _rss.php. So I would say no need to change anything in config.php 🙂

  • Like 2
Posted

Thanks again @monollonom. That helps a lot. Still trying to scope out what output stategy is best for a portfolio site I've built as static html, with possible a small store at a future date. I would like to ensure my GSAP scroll animations work properly so controlling JS and CSS from one working base seems better than using lots of include templates, Idk... Rather new to this. 

By the way, I had a look at your site. Your work is very impressive, well done. Did you build any of those sites with ProcessWire by any chance? 
 

  • Like 1
Posted

Hi,

as i stongly agree with @monollonom about this checkbox to use a different, say frame, than the usual _main and the fact that in general you don't need a specific config, there are ready, init and so on for this i'd like to add a few things

change your  _main frame would useful for rss feed, sitemap; well xml files 🙂 but also for modals for example (and sometimes for dynamic css or js files) as you often need a lighter when not totally different html head and quite often too far less js files to the bottom of the file but not at all for the home page
if you have a closer look to what this _main file allows with marlup regions you'll see that it goes far above a main div with an id you can use in every template with totally (or not) diffeerent html content and around, above and below, div (or else) you will have (or not) on every template/page

even before diving deep into the markup regions world, first thing first, as this _main.php file is a php one let's take a simple example, the homepage
quite often you have a section name hero (i still don't know why...) with a big image, carrousel, or any gsap animated witchcraft 🙂 and on top of this other page a simpler and horter image with or not a title sometimes a breadcrumbs...
well, before that main div/section you will (or not) use everuwhere, why not simply use php... if page id is 1 (or template == home) hop, your big whatever it is and else what you need in the other page
of course, is there are some pages, say, in your case your futur shop, for which you need a different head part, well you see where i'm going... and you may have noticed i quite often said "or not", this is processwire way of life 🙂, nothing is  compulsory it is all about your logic, its own logic is just here to help you do things faster than if you had to write every single thing by yourself but you can think exactly the same way as if you did

and now if you dive a little deeper into markup regions, its optional attributes, you'll see how powerful it is

have a nice day (and a great pw journey :))

  • Like 1
Posted
12 hours ago, ai_slop said:

By the way, I had a look at your site. Your work is very impressive, well done. Did you build any of those sites with ProcessWire by any chance? 

Thanks! All of them are built using ProcessWire, it's my tool of choice ever since I got introduced to it close to 10 years ago 🙂

  • Like 1
Posted

Thanks @virtualgadjo, appreciate the advice.

It's a little difficult at first (for a newcomer, at least) to wrap one's head around markup regions but it sounds flexible and more future proof than sticking with direct output and includes.

You're right about the JS and animation overhead. That's the main thing that's bothering me. For my site, the homepage is animation and image heavy so I'm wondering whether I should just serve it as a static page without _main.php (with a few project thumbnail <a> tags thown in) and then use _main.php for the other pages. 

The idea would be to avoid cutting out bits of scripts from my existing static home page and putting them into templates for appendng - only to append them back in with markup regions.

I guess serving home.php as the homepage wouldnt impact the URLs or anything


 

Posted

Hi @ai_slop

if you knew how much i agree with this, of course my very first website with pw was made with my usual includes of header and footer php files but as soon as i decided to try and understand the various output strategies and tried the markup regions it was a no return back path 😀

what you describe about your homepage is somthing i often run into too, my solution varies from the things i need for the hom page, sometimes i can even be e script tag with various things far easier to deal with in the template and that would be a bit too much in the website general js file
in this case i use the trick i spoke about, my script tag surrounded by a simple if page id is 1
but when i'm a little less lazy i sometimes even use something pw allows me to do, when i need ereally specific heavy css for example based on some pages parent, ids or even a variable value, i add the type i need to the config, i.e

$config->contentTypes = array_merge($config->contentTypes,
    array(
        'css' => 'text/css'
    )
);

this way you'll have a new header type added to the Content-type combo box choice in the template and a php file with a css type header but having access to pw api, this allows you some pretty acrobatic things 🙂
but well, to be honest, i more often use the old php if to load some files or even output script tags

keeping in mind that the _main.php file is appended at the end of the template files, you can also submit content, script, files and so on output or not, relying on a var you define in the template itself, actually, the kind of things you could do even in a not pw structure but taking advantage of pw api

have a nice day

  • Like 1
Posted

So many ways to create great websites.
I use Markup Regions too. In _main.php I have regions:
 

// in <head>
<region id="regHeadCSS">
</region>

// just above the closing </body> tag  
<region id="regFooterScripts">
</region>

then on a per template basis I can "pw-append" any CSS or JS specific to an individual template. If no extra CSS or JS needed, no problem.

  • Like 2
Posted

hi,
can't agree more, so many ways..s and it's exactly why processwire is so special, it offers you a lot of ways to do things, including when it exists a simple php piece of code
i must admit i often go for  pure php when possible and not to verbose and thank you so much pw for letting me do so... well and for so many other things like custom page classes, hooks, i have to stop here else the list will be far too long 🤣

have a nice day

  • Like 1
Posted

Thanks @virtualgadjo. The contentTypes tip looks interesting, though I'm not yet advanced enough yet to fully understand it, but I'll get there eventually! 😄

Ah yes @psy, I forgot about the <region> tags - good idea. I was just going to try something like <script pw-id='js' ......  pw-optional></script> but I'm not sure if that would work with prepending, before, after, etc and if the tags don't match. The region approach looks cleaner. Thanks!

  • Like 1

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
×
×
  • Create New...