Jump to content

First time with Markup Regions - no luck getting it to work


evanmcd
 Share

Recommended Posts

Hi all,

Just found my first use case for new Markup Regions (at least I think that's what they're being called) feature. Unfortunately, I haven't been able to get it working.

I'm using 3.0.57 and have added the 

$config->useMarkupRegions = true;

line to my config file.

Next, I put the id in my head tag  like so:

<html lang="en">
	<head id="html-head">

Then the markup in the template file (the head tag is in top.php):

<?php include("inc/top.php"); ?>
<head id="html-head" class="pw-append">
  <link rel="stylesheet" type="text/css" href="/site/templates/css/calculator.css">
</head>

When I reload the page that uses the above template, I get that unprocessed code output right after the output of my top.php file - in other words exactly what would happen if there were no such thing as Markup Regions.

Am I missing something?

I've read through the post here, and I seem to be doing everything needed.

Thanks for any help.

Link to comment
Share on other sites

The following quote from the blog post is useful in understanding how your templates need to be structured in order for Markup Regions to work:

Quote

When ProcessWire renders a page, it now asks the question: does any markup appear before the doctype or <html> element? And if it does, does any of it reference "id" attributes or have "pw-" prefix classes? If so, it processes them as markup regions, letting you do all that's mentioned in this post.

So the general rule is: the place where you define your 'original' markup regions (that you will append to, etc, in your template files) needs to have the doctype or <html> element in it, and it needs to be the last piece of markup to be rendered.

That's why your markup regions would typically be originally defined in an auto-appended "_main.php" so that it is rendered last, and any markup that you are echoing or outputting in your template files will reference those regions and appear before the doctype/<html> of _main.php.

  • Like 2
Link to comment
Share on other sites

Quote

<?php include("inc/top.php"); ?>
<head id="html-head" class="pw-append">
  <link rel="stylesheet" type="text/css" href="/site/templates/css/calculator.css">
</head>

 

@evanmcd  You say

Quote

the head tag is in top.php

So it seems you get the head tag twice.

Link to comment
Share on other sites

Oh no problem at all @ottogal.

Just tried moving the appended region code above my top.php and it worked as @Robin S predicted. Not sure why I didn't just try that before :huh:

In any case, thanks for the help. I see myself using markup regions with all my sites going forward. So much cleaner that other methods.

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